#include "mainwindow.h"
#include "ui_mainwindow.h"
extern  QString REASON;//
extern QString REASONID;//
extern QDateTime FORMDATE;
static int nCurScroller=0; //翻页时的当时滑动条位置
static int pageValue = 4; // 一页显示条数
#define OLD_LED 1
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    initntp();
    read_ini();
    initialization();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::initntp()
{
    QString serip=sysInfo->serverIp;
    char cmd[100];
    sprintf(cmd,"ntpdate  %s",serip.toLatin1().data());
    ::system(cmd);
    //qDebug()<<"initntp";
}

void MainWindow::read_ini()
{
    serIP_flag=false;
    ser_IP1=sysInfo->serverIp;
    ser_IP2=sysInfo->serverIpBei;
    QString begingti,endti;
    QTime start,end;
    QFile file("camera.ini");
    if(file.open(QFile::ReadOnly))
    {
        begingti=file.readLine().trimmed().left(5);
        endti=file.readLine(  ).trimmed().left(5);
        park_form_flag=file.readLine().trimmed();
        start=QTime::fromString(begingti,"hh:mm");
        end=QTime::fromString(endti,"hh:mm");
        qDebug()<<"camera_inpic:"<<begingti<<"camera_outpic"<<endti;
        file.close();
    }else{
        QFile file1("camera.ini");
        if(file1.open(QFile::WriteOnly))
        {
            QTextStream out1(&file1);
            out1<<"08:00"<<"\r\n"<<"21:00"<<"\r\n"<<"N";
            out1.seek(out1.pos());//定位文件当前
            //file.write("\r\n");//换行符
            file.close();
        }
        QString str,mtr;
        str="08:23";
        mtr="21:23";
        start=QTime::fromString(str,"hh:mm");
        end=QTime::fromString(mtr,"hh:mm");
        park_form_flag="N";
    }
    ui->timeEdit_begin->setTime(start);
    ui->timeEdit_end->setTime(end);
    park_form_set(park_form_flag);
    qDebug()<<"read_ini";
}

void MainWindow::initialization()
{
    //初始化串口
    this->initComDevice();
    //udp
    this->initUdp();
    //web
    this->initWeb();
    //ftp
    this->initFtp();
    //界面设置
    this->initPaint();
    //初始化车牌识别摄像机连接
    this->initCamera();
    //定时器】
    this->initTimer();
    //文件操作
    this->initFile();
    //连接Mysql数据库
    //this->initMysdate();
}

void MainWindow::initComDevice()
{
    QString comName[4] = {"/dev/ttyO2","/dev/ttyO4","/dev/ttyO1","/dev/ttyO5"};
    //初始化串口设备1
    switch(ticketDevInfo->comDev[0].com_type)
    {
    case 1:
        break;
    case 2:
        switch(ticketDevInfo->comDev[0].com_model)
        {
        case 1:
            break;
        case 2:
            fdCom1 = openPort(comName[0],9600,8,1,"N");
            notifierCom1 = new QSocketNotifier(fdCom1,QSocketNotifier::Read,this);
            scanInDev = new scanDev(fdCom1);
            connect(notifierCom1,SIGNAL(activated(int)),this,SLOT(com1RecProcess()));
            qDebug()<<comName[0]<<"com1-2-2-SK-9600";
            break;
        default:
            break;
        }
        break;
    case 3:
        break;
    case 4:
        break;
    default:
        break;
    }
    //初始化串口设备2
    switch(ticketDevInfo->comDev[1].com_type)
    {
    case 1:
        break;
    case 2:
        switch(ticketDevInfo->comDev[1].com_model)
        {
        case 1:
            break;
        case 2:
            fdCom2 = openPort(comName[1],9600,8,1,"N");
            notifierCom2 = new QSocketNotifier(fdCom2,QSocketNotifier::Read,this);
            scanOutDev = new scanDev(fdCom2);
            connect(notifierCom2,SIGNAL(activated(int)),this,SLOT(com2RecProcess()));
            qDebug()<<comName[1]<<"com2-2-2-SK-9600";
            break;
        default:
            break;
        }
        break;
    case 3:
        break;
    case 4:
        break;
    default:
        break;
    }
    connect(this,SIGNAL(send_icnum(QString)),this,SLOT(icRecProcess(QString)));
    connect(this,SIGNAL(send_serIP_change()),this,SLOT(serIP_change()));
}

void MainWindow::initWeb()
{
    CAR_SEAT=QString::number(100);
    this->myDb = new datebase();
    TurnClassTime=QDateTime::currentDateTime();//换班时间
    picput_flag=0;//上传图片标志
    my_network=new network(this->myDb);

    down_network = new Car_Product(this->myDb);
    this->down_network->start();
    connect(down_network,SIGNAL(MsgSignal(QString)),this,SLOT(CarDownProcess(QString)));
    connect(this,SIGNAL(send_msg(QString)),down_network,SLOT(receiv_Msg(QString)));

    //获取时间
    my_network->webInforTime = new QNetworkAccessManager(this);
    QObject::connect(my_network->webInforTime, SIGNAL(finished(QNetworkReply*)),
                     this, SLOT(TimefinishedSlot(QNetworkReply*)));

    //固定车更新接口
    my_network->webInforCar  = new QNetworkAccessManager(this);
    QObject::connect(my_network->webInforCar, SIGNAL(finished(QNetworkReply*)),
                     this, SLOT(CarfinishedSlot4(QNetworkReply*)));

    //通行记录上传接口
    my_network->webInforInOutup = new QNetworkAccessManager(this);
    //通行记录下载接口
    my_network->webInforInOutdown = new QNetworkAccessManager(this);
    QObject::connect(my_network->webInforInOutdown, SIGNAL(finished(QNetworkReply*)),
                     this, SLOT(InOutfinishedSlot6(QNetworkReply*)));
    //车位信息下载
    my_network->webInforcarstall = new QNetworkAccessManager(this);
    QObject::connect(my_network->webInforcarstall, SIGNAL(finished(QNetworkReply*)),
                     this, SLOT(carstallfinishedSlot(QNetworkReply*)));

    my_network->webInforcarbind = new QNetworkAccessManager(this);
    //固定车车位信息绑定下载接口
    QObject::connect(my_network->webInforcarbind, SIGNAL(finished(QNetworkReply*)),
                     this, SLOT(carbindfinishedSlot(QNetworkReply*)));
    qDebug()<<"initWeb";
}

void MainWindow::initPaint()
{

    ui->stackedWidget->setCurrentIndex(0);
    pic_name="images/pic.png";
    ui->lineEdit_IN_CAR->installEventFilter(this);
    QRegExp regExp("[A-Za-z0-9]{0,6}");
    ui->lineEdit_IN_CAR->setValidator(new QRegExpValidator(regExp,this));
    connect(&w,SIGNAL(input_text_pass(QString)),this,SLOT(write_back_str(QString)));
    //update();
    /*ui->label_parkTime->setFrameShape(QFrame::WinPanel);
    ui->label_parkTime->setFrameShadow(QFrame::Sunken);
    ui->label_beginT->setFrameShape(QFrame::WinPanel);
    ui->label_beginT->setFrameShadow(QFrame::Sunken);
    ui->label_endT->setFrameShape(QFrame::WinPanel);
    ui->label_endT->setFrameShadow(QFrame::Sunken);
*/
    ui->label_turn_begin->setFrameShape(QFrame::WinPanel);
    ui->label_turn_begin->setFrameShadow(QFrame::Sunken);
    ui->label_turn_end->setFrameShape(QFrame::WinPanel);
    ui->label_turn_end->setFrameShadow(QFrame::Sunken);
    ui->label_car_cunt->setFrameShape(QFrame::WinPanel);
    ui->label_car_cunt->setFrameShadow(QFrame::Sunken);
    ui->label_shoufei->setFrameShape(QFrame::WinPanel);
    ui->label_shoufei->setFrameShadow(QFrame::Sunken);
    ui->label_widgetcount->setFrameShape(QFrame::WinPanel);
    ui->label_widgetcount->setFrameShadow(QFrame::Sunken);
    ui->label_shou_start->setFrameShape(QFrame::WinPanel);
    ui->label_shou_start->setFrameShadow(QFrame::Sunken);
    ui->label_shou_end->setFrameShape(QFrame::WinPanel);
    ui->label_shou_end->setFrameShadow(QFrame::Sunken);
    ui->label_shou_count->setFrameShape(QFrame::WinPanel);
    ui->label_shou_count->setFrameShadow(QFrame::Sunken);
    /***********/
    ui->label_pagenum->setFrameShape(QFrame::WinPanel);
    ui->label_pagenum->setFrameShadow(QFrame::Sunken);
    ui->label_parkseat->setFrameShape(QFrame::WinPanel);
    ui->label_parkseat->setFrameShadow(QFrame::Sunken);
    ui->label_parktype->setFrameShape(QFrame::WinPanel);
    ui->label_parktype->setFrameShadow(QFrame::Sunken);
    ui->label_passflag->setFrameShape(QFrame::WinPanel);
    ui->label_passflag->setFrameShadow(QFrame::Sunken);
    ui->label_tempcarin->setFrameShape(QFrame::WinPanel);
    ui->label_tempcarin->setFrameShadow(QFrame::Sunken);
    ui->label_firstdown->setFrameShape(QFrame::WinPanel);
    ui->label_firstdown->setFrameShadow(QFrame::Sunken);
    ui->label_vehicleflag->setFrameShape(QFrame::WinPanel);
    ui->label_vehicleflag->setFrameShadow(QFrame::Sunken);
    ui->label_savepicture->setFrameShape(QFrame::WinPanel);
    ui->label_savepicture->setFrameShadow(QFrame::Sunken);
    ui->label_passwd_message->setFrameShape(QFrame::WinPanel);
    ui->label_passwd_message->setFrameShadow(QFrame::Sunken);
    stackpage();
    //connect(ui->pushButton_setting_up,SIGNAL(clicked()),this,SLOT(stackpage()));
    //connect(ui->pushButton_setting_down,SIGNAL(clicked()),this,SLOT(stackpage()));
    /**************/
    ui->label_parkTime->setAlignment(Qt::AlignCenter);
    ui->label_beginT->setAlignment(Qt::AlignCenter);
    ui->label_endT->setAlignment(Qt::AlignCenter);
    ui->label_car_cunt->setAlignment(Qt::AlignCenter);
    ui->label_turn_begin->setAlignment(Qt::AlignCenter);
    ui->label_turn_end->setAlignment(Qt::AlignCenter);
    ui->pushButton_carIn->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_carOut->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_open_in->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_open_out->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_in_zoom->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_out_zoom->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_OK->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_up->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_turnok->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_turnquit->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_down->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_allday->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_allTime->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_set->setFocusPolicy(Qt::NoFocus);
    ui->label_picture_in->setScaledContents(true);
    ui->label_picture_out->setScaledContents(true);
    ui->label_InImage->setScaledContents(true);

    QRegExp double_rx100("10000|([0-9]{0,4})");
    ui->lineEdit_day->setValidator(new QRegExpValidator(double_rx100, ui->lineEdit_day));
    ui->lineEdit_day->setVisible(false);
    ui->lineEdit_seart->setValidator(new QRegExpValidator(double_rx100, ui->lineEdit_day));
    ui->lineEdit_seart->setVisible(false);

    QRegExp double_rx1000("1000|([0-9]{1,3}[\.][0-9]{1,1})");
    ui->lineEdit_fee_half->setValidator(new QRegExpValidator(double_rx1000, ui->lineEdit_fee_half));
    ui->lineEdit_fee_one->setValidator(new QRegExpValidator(double_rx1000, ui->lineEdit_fee_one));
    ui->lineEdit_fee_tall->setValidator(new QRegExpValidator(double_rx1000, ui->lineEdit_fee_tall));
    ui->lineEdit_fee_half->setVisible(false);
    ui->lineEdit_fee_one->setVisible(false);
    ui->lineEdit_fee_tall->setVisible(false);

    QRegExp double_rx10000("10000000|([0-9]{0,7})");
    ui->lineEdit_passwd->setValidator(new QRegExpValidator(double_rx10000, ui->lineEdit_passwd));
    ui->lineEdit_passwd2->setValidator(new QRegExpValidator(double_rx10000, ui->lineEdit_passwd2));
    //ui->lineEdit_passwd->setVisible(false);

    ui->lineEdit_passwd->setEchoMode(QLineEdit::Password);
    ui->lineEdit_passwd->setStyleSheet("lineedit-password-character:42");
    ui->lcdNumber_passwd->setVisible(false);
    ui->lineEdit_passwd1->setVisible(false);
    ui->lineEdit_passwd2->setVisible(false);
    ui->lineEdit_passwd3->setVisible(false);

    ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui->tableWidget_2->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->tableWidget_2->setEditTriggers(QAbstractItemView::NoEditTriggers);

    ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Interactive);
    ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Interactive);
    ui->tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

    ui->tableWidget->verticalScrollBar()->setStyleSheet("QScrollBar{background:red; width: 30px;border:2px solid transparent; border-radius:5px;}");
    //ui->tableWidget->horizontalScrollBar()->setFixedHeight(150);
    //ui->tableWidget->verticalScrollBar()->setStyleSheet("QScrollBar{background:red; width:10px;}");
    //ui->tableWidget->verticalScrollBar()->setMaximumWidth(100);
    /*ui->tableWidget->verticalScrollBar()->setStyleSheet("QScrollBar:vertical {"
                                                           "width: 30px;"
                                                        "}");*/
    connect(ui->tableWidget->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(onHeaderClicked(int)));
    connect(ui->tableWidget_2->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(Widget2Clicked(int)));
    /*QImageReader reader;
    reader.setFileName("./images/car.jpg");
    QSize imagesize = reader.size();
    imagesize.scale(size(),Qt::KeepAspectRatio);
    reader.setScaledSize(imagesize);
    QImage image =reader.read();
    QPixmap img= QPixmap::fromImage(image);*/
    ui->label_picture_in->setPixmap(QPixmap("./images/car.jpg"));
    ui->label_picture_out->setPixmap(QPixmap("./images/car.jpg"));
    ui->lcdNumber->installEventFilter(this);
    ui->lcdNumber_2->installEventFilter(this);
    ui->label_turn_begin->installEventFilter(this);
    ui->label_turn_end->installEventFilter(this);
    ui->label_localIP->setText(sysInfo->localIp);
    gb2312 = QTextCodec::codecForName("GB2312");
    utf8 = QTextCodec::codecForName("UTF-8");
    park_type_set(1);

    park_model_set(sysInfo->model);
    park_parktype_set(sysInfo->park_type);
    park_camera_set(sysInfo->park_camera);
    park_pass_set(sysInfo->passFlag);
    park_tempcarin_set(sysInfo->tempCarIn);
    park_vehicle_set(sysInfo->vehicleFlag);
    park_savepic_set(sysInfo->savePicture);
    park_firstdown_set(sysInfo->first_down);
    park_fee_set(0);
    park_passwd(0);
    qDebug()<<"initPaint";
}

void MainWindow::initCamera()
{
    //显示屏及语音提示
    QByteArray sendArray;
    displayData_t dispInfo;
    sendArray = gb2312->fromUnicode(sysInfo->galleryName);
    this->cameraIn = new camera();
    this->cameraOut = new camera();

    if(!sysInfo->cameraInIp.isEmpty())
    {
        //初始化车牌识别入口摄像机连接
        connect(this->cameraIn,SIGNAL(carNumberRecEnd(QString,QPixmap*)),SLOT(carNumberIn_Slot(QString,QPixmap*)));
        connect(this,SIGNAL(send_cameraIn(QString)),this->cameraIn,SLOT(longsocket_in(QString)));
        connect(this->cameraIn,SIGNAL(sendMsg(QDateTime)),this,SLOT(write_back_in(QDateTime)));
        //摄像机TCP
        this->cameraIn->socket_link(sysInfo->cameraInIp);

        cameraIn->socket_short_syncTime();
        dispInfo.audioStr = sysInfo->galleryName;
        dispInfo.DispelayStr[0] = "车牌识别  一车一杆  减速慢行";
        dispInfo.DispelayStr[1] = "\\DL月\\DD日";
        dispInfo.DispelayStr[2] = "\\DH时\\DM分";
        dispInfo.DispelayStr[3]=sysInfo->galleryName+"   ";
        this->cameraIn->socket_short_display(&dispInfo);//开机初始化屏幕信息
        ///同步时间
    }else{
        if(!sysInfo->cameraInIpBei.isEmpty())
        {
            //初始化车牌识别入口摄像机连接
            connect(this->cameraIn,SIGNAL(carNumberRecEnd(QString,QPixmap*)),SLOT(carNumberIn_Slot(QString,QPixmap*)));
            connect(this,SIGNAL(send_cameraIn(QString)),this->cameraIn,SLOT(longsocket_in(QString)));
            connect(this->cameraIn,SIGNAL(sendMsg(QDateTime)),this,SLOT(write_back_in(QDateTime)));
            //摄像机TCP
            this->cameraIn->socket_link(sysInfo->cameraInIpBei);
            //this->cameraIn->socket_short_display(INFO_ADDR,sendArray);
        }
    }

    if(!sysInfo->cameraOutIp.isEmpty())
    {
        //初始化车牌识别出口摄像机连接
        connect(this->cameraOut,SIGNAL(carNumberRecEnd(QString,QPixmap*)),SLOT(carNumberOut_Slot(QString,QPixmap*)));
        connect(this,SIGNAL(send_cameraOut(QString)),this->cameraOut,SLOT(longsocket_in(QString)));
        connect(this->cameraOut,SIGNAL(sendMsg(QDateTime)),this,SLOT(write_back_out(QDateTime)));
        //摄像机TCP
        this->cameraOut->socket_link(sysInfo->cameraOutIp);
        cameraOut->socket_short_syncTime();
        dispInfo.audioStr = sysInfo->galleryName;
        dispInfo.DispelayStr[0] = "车牌识别  一车一杆  减速慢行";
        dispInfo.DispelayStr[1] = "\\DL月\\DD日";
        dispInfo.DispelayStr[2] = "\\DH时\\DM分";
        dispInfo.DispelayStr[3]=sysInfo->galleryName+"   ";
        this->cameraOut->socket_short_display(&dispInfo);//开机初始化屏幕信息
    }else{
        if(!sysInfo->cameraOutIpBei.isEmpty())
        {
            //初始化车牌识别出口摄像机连接
            connect(this->cameraOut,SIGNAL(carNumberRecEnd(QString,QPixmap*)),SLOT(carNumberOut_Slot(QString,QPixmap*)));
            connect(this,SIGNAL(send_cameraOut(QString)),this->cameraOut,SLOT(longsocket_in(QString)));
            connect(this->cameraOut,SIGNAL(sendMsg(QDateTime)),this,SLOT(write_back_out(QDateTime)));
            //摄像机TCP
            this->cameraOut->socket_link(sysInfo->cameraOutIpBei);
            //this->cameraOut->socket_short_display(INFO_ADDR,sendArray);
        }
    }
    //网络发送请求时间
    /*if(sysInfo->model!=3)
    {
        my_network-cgiFormResultType cgiFormInteger( char *name, int *result, int defaultV)>GetTime();
    }
    */
    qDebug()<<"initCamera";
}

void MainWindow::initTimer()
{
    timer_update=new QTimer(this);//显示屏定时发送时间
    connect(timer_update,SIGNAL(timeout()),this,SLOT(dispUpdata()));//界面时间
    timer_update->start(10000);

    timer_update2=new QTimer(this);//显示屏定时发送时间
    connect(timer_update2,SIGNAL(timeout()),this,SLOT(dispUpdata2()));//界面时间
    timer_update2->start(10000);

    timer_dispalay=new QTimer(this);
    connect(timer_dispalay,SIGNAL(timeout()),this,SLOT(disPaint()));//界面时间
    timer_dispalay->start(60000);
    time_flag=false;

    ui->lcdNumber_2->setNumDigits(11);
    ui->lcdNumber_2->display(QDateTime::currentDateTime().toString("MM-dd hh:mm"));
/*
    timer_down=new QTimer(this);//固定车下载图片上传
    connect(timer_down,SIGNAL(timeout()),this,SLOT(carupdate_send()));//下载固定车
    timer_down->start(2000);
*/
    timer_in=new QTimer(this);//入口起杠
    connect(timer_in,SIGNAL(timeout()),this,SLOT(camera_in()));//入口起杠

    timer_out=new QTimer(this);//出口起杠
    connect(timer_out,SIGNAL(timeout()),this,SLOT(camera_out()));//出口起杠

    this->watch_dog =new MyWatch();//看门狗
    timer_dog =new QTimer(this);
    connect(timer_dog,SIGNAL(timeout()),this,SLOT(DogLink()));
    timer_dog->start(40000);

    timer_receive=new QTimer(this);//入口摄像机重连信号
    connect(timer_receive,SIGNAL(timeout()),this,SLOT(CameraInRecive()));

    timer2_receive=new QTimer(this);//出口摄像机重连信号
    connect(timer2_receive,SIGNAL(timeout()),this,SLOT(CameraOutRecive()));

    timer_carIn=new QTimer(this);//单通道入口时间
    connect(timer_carIn,SIGNAL(timeout()),this,SLOT(car_inClear()));

    timer_carOut=new QTimer(this);//单通道出口时间
    connect(timer_carOut,SIGNAL(timeout()),this,SLOT(car_outClear()));

    timer_CarDown=new QTimer(this);//下载固定车线程
    connect(timer_CarDown,SIGNAL(timeout()),this,SLOT(Car_downLink()));
    timer_CarDown->start(10000);

    timer_recordDown=new QTimer(this);//下载车辆通行记录
    connect(timer_recordDown,SIGNAL(timeout()),this,SLOT(info_downLink()));
    timer_recordDown->start(10000);

    timer_recordup=new QTimer(this);//上传车辆通行记录
    connect(timer_recordup,SIGNAL(timeout()),this,SLOT(info_upLink()));
    timer_recordup->start(10000);

    timer_bind_down=new QTimer(this);//下载车辆车位绑定信息
    connect(timer_bind_down,SIGNAL(timeout()),this,SLOT(seatbind_downLink()));
    timer_bind_down->start(15000);

    timer_stall_down=new QTimer(this);//下载车位信息
    connect(timer_stall_down,SIGNAL(timeout()),this,SLOT(car_stall_downLink()));
    timer_stall_down->start(30000);

    timer_quit_carNumberIn=new QTimer(this);//屏蔽抓拍功能
    connect(timer_quit_carNumberIn,SIGNAL(timeout()),this,SLOT(quit_carNumberIn()));
    carNumberIn_flag=true;

    timer_quit_carNumberOut=new QTimer(this);//屏蔽抓拍功能
    connect(timer_quit_carNumberOut,SIGNAL(timeout()),this,SLOT(quit_carNumberOut()));
    carNumberOut_flag=true;
    qDebug()<<"initTimer";
}

void MainWindow::initFile()
{
    filelink = new FileManage();
    Image_link = new Put_Image(this->myDb,this->filelink);
    connect(Image_link,SIGNAL(PutSignal(bool)),this,SLOT(PutImageProcess(bool)));
    qDebug()<<"initFile";
}

void MainWindow::initMysdate()
{
    this->mysql_link = new MysqlLink();
    timer_dataBaseLink = new QTimer(this);
    connect(timer_dataBaseLink,SIGNAL(timeout()),this,SLOT(dataBaseLink()));
    if(sysInfo->model != 3)
    {
        timer_dataBaseLink->start(5000);
    }
    qDebug()<<"initMysdate";
}

void MainWindow::carNumberIn_Slot(QString carNum, QPixmap *pic)  ///入口抓拍
{
    bool mes,res,nes;
    this->inPixmap = *pic;
    if(sysInfo->savePicture==1)
    {
        pic->save(QString("in.jpg"),"JPG");
    }
    QDateTime time = QDateTime::currentDateTime();
    QString pound_no = time.toString("yyyy-MM-dd-hh-mm-ss-zzz");
    Camera_picIn=pound_no+"1"+".bmp";
    QString pic_date=time.toString("yyyyMMdd");
    ui->label_picture_in->setPixmap(this->inPixmap);
    //carNum="晋APR356";
    if(!carNumberIn_flag)
    {
        return;
    }
    ui->pushButton_carIn->setText(carNum);
    if(sysInfo->cameraInIp.isEmpty())
    {
        return;
    }
    displayData_t info;
    int j;
    info.audioStr.clear();
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }

    if(carNum.isEmpty())
    {
        if(IcCardNum.isEmpty())
        {
            info.audioStr = "车牌未识别请倒车重新识别  ";
            info.DispelayStr[3] = info.audioStr;
            this->cameraIn->socket_short_display(&info);
            if(sysInfo->savePicture==1)
            {
                filelink->copyFileToDate(pic_date,CARIN,Camera_picIn);
                res=this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picIn,carNum,pic_date);
            }
            timer_update->start(10000); ///启动还原屏幕信息函数
            return;
        }else{
            carNum=IcCardNum;
            ui->pushButton_carIn->setText(carNum);
            //QString per_addres="";
            //this->myDb->writeCarInLog(&this->myDb->sqlite_db_bei,carNum,Camera_picIn,"临时车",per_addres,"已入",per_addres);
        }
    }
    Car_InVehicle=carNum;
    if(sysInfo->passFlag==1)
    {
        int car_res;
        car_res=showMap(carNum,"入");
        if(car_res==1)
        {
            qDebug()<< carNum;
        }else if(car_res==0)
        {
            car_map[carNum] = Carployee("入",QDateTime::currentDateTime());
        }else if(car_res==2){
            //QByteArray sendArray;
            info.audioStr=QString("请%1秒后重新识别").arg(pass_flag_heart);
            info.DispelayStr[3] = info.audioStr;
            this->cameraIn->socket_short_display(&info);
            timer_update->start(10000); ///启动还原屏幕信息函数
            return;
        }
    }
    ticketCheck_t carInfo1,carInfo3;
    QString use_code;
    switch(sysInfo->model)
    {
    case 1 :
        mes=this->myDb->car_chek(&this->myDb->sqlite_db,&carInfo1,QString::number(sysInfo->vehicleFlag),carNum);
        if(mes)//固定车
        {
           //判断是否有车位,有->取出车位
            ui->pushButton_carIn->setText("固定车"+QString(" ")+carNum);
            QStringList stall_code=this->myDb->select_stall_code(&this->myDb->sqlite_db,carNum);

            if(stall_code.count()>0)//绑定车位
            {

                use_code=this->myDb->check_stall_car(&this->myDb->sqlite_db_bei,carNum,stall_code);
                qDebug()<<"use_code"<<use_code;
                if(use_code=="null")//占用车位
                {
                    info.audioStr = QObject::tr("固定车").append(carNum).append("车位已满");
                    info.DispelayStr[3] = info.audioStr;
                    this->cameraIn->socket_short_display(&info);
                    makeAudio(info);
                }
                else//没有占用车位
                {
                    if(sysInfo->savePicture==1)
                    {
                        filelink->copyFileToDate(pic_date,CARIN,Camera_picIn);
                        res=this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picIn,carNum,pic_date);
                    }
                    nes=this->myDb->writeCarInLog(&this->myDb->sqlite_db_bei,carNum,Camera_picIn,"固定车",use_code,"已入",use_code);
                    if(nes){
                        qDebug()<<"^^^^^^^^^入口通行记录更新完成^^^^^^^^^^";
                    }
                    info.audioStr = QObject::tr("固定车").append(carNum).append("欢迎光临");
                    info.DispelayStr[3] = info.audioStr;
                    this->cameraIn->socket_short_display(&info);
                    makeAudio(info);
                    timer_in->start(300);
                }              
            }
            else //没有绑定车位
            {
                if(sysInfo->savePicture==1)
                {
                    filelink->copyFileToDate(pic_date,CARIN,Camera_picIn);
                    res=this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picIn,carNum,pic_date);
                }
                nes=this->myDb->writeCarInLog(&this->myDb->sqlite_db_bei,carNum,Camera_picIn,"固定车",use_code,"已入",use_code);
                if(nes){
                    qDebug()<<"^^^^^^^^^入口通行记录更新完成^^^^^^^^^^";
                }
                info.audioStr = QObject::tr("固定车").append(carNum).append("欢迎光临");
                info.DispelayStr[3] = info.audioStr;
                this->cameraIn->socket_short_display(&info);
                makeAudio(info);
                timer_in->start(300);
            }
            info_upLink();
        }else{
            qDebug()<<"*****临时车**********";
            info.audioStr = QObject::tr("临时车").append(carNum).append("禁止通行");
            info.DispelayStr[3] = info.audioStr;
            this->cameraIn->socket_short_display(&info);
            makeAudio(info);
        }
        break;
    case 2:
        my_network->carIn(carNum,Camera_picIn);
        if(sysInfo->savePicture==1)
        {
            filelink->copyFileToDate(pic_date,CARIN,Camera_picIn);
            res=this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picIn,carNum,pic_date);
        }
        break;
    case 3:
        timer_update->stop();
        mes=this->myDb->car_chek(&this->myDb->sqlite_db,&carInfo3,QString::number(sysInfo->vehicleFlag),carNum);
        if(mes)//固定车
        {
            ui->pushButton_carIn->setText(carInfo3.car_type+QString(" ")+carNum);

            if(carInfo3.ticketReturn=="nomal")//固定车
            {
                QStringList stall_code=this->myDb->select_stall_code(&this->myDb->sqlite_db,carNum);
                //QString stall_code=this->myDb->select_stall_code_new(&this->myDb->sqlite_db,carNum);
                if(stall_code.count()>0)//固定车绑定车位
                //if(!stall_code.isEmpty())
                {
                    use_code=this->myDb->check_stall_car(&this->myDb->sqlite_db_bei,carNum,stall_code);
                    qDebug()<<"use_code"<<use_code;
                    if(use_code=="null")//占用车位
                    {
                        qDebug()<<"固定车"<<carNum<<"-车位已满-无法入场";
                        info.audioStr = "固定车"+carNum+" 车位已满 无法入场";
                        info.DispelayStr[3] = info.audioStr;
                        makeAudio(info);
                        this->cameraIn->socket_short_display(&info);
                    }else{
                        if(sysInfo->savePicture==1)
                        {
                            filelink->copyFileToDate(pic_date,CARIN,Camera_picIn);
                            this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picIn,carNum,pic_date);
                        }
                        nes=this->myDb->writeCarInLog(&this->myDb->sqlite_db_bei,carNum,Camera_picIn,"固定车",use_code,"已入",use_code);
                        if(nes){
                            qDebug()<<"固定车-绑定车位-入口通行记录更新完成"<<sysInfo->savePicture;
                        }
                        info.audioStr = QObject::tr("固定车").append(carNum).append("欢迎光临");
                        info.DispelayStr[3] = info.audioStr;
                        makeAudio(info);
                        this->cameraIn->socket_short_display(&info);
                        timer_in->start(300);
                    }
                }
                else//固定车，没有绑定车位
                {
                    if(sysInfo->savePicture==1)
                    {
                        filelink->copyFileToDate(pic_date,CARIN,Camera_picIn);
                        this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picIn,carNum,pic_date);
                    }
                    nes=this->myDb->writeCarInLog(&this->myDb->sqlite_db_bei,carNum,Camera_picIn,"固定车",use_code,"已入",use_code);
                    if(nes){
                        qDebug()<<"固定车-没有绑定车位-入口通行记录更新完成"<<sysInfo->savePicture;
                    }
                    info.audioStr = QObject::tr("固定车").append(carNum).append("欢迎光临");
                    info.DispelayStr[3] = info.audioStr;
                    makeAudio(info);
                    this->cameraIn->socket_short_display(&info);
                    timer_in->start(300);
                }
                info_upLink();
            }else{
                info.audioStr = QObject::tr("临时车").append(carNum).append(carInfo3.ticketReturn);
                info.DispelayStr[3] = info.audioStr;
                makeAudio(info);
                this->cameraIn->socket_short_display(&info);
            }
        }
        else{//临时车
            info.audioStr = QObject::tr("临时车").append(carNum).append("禁止通行");
            info.DispelayStr[3] = info.audioStr;
            makeAudio(info);
            this->cameraIn->socket_short_display(&info);
        }
        break;
    case 4 :
        my_network->carIn(carNum,Camera_picIn);
        if(sysInfo->savePicture==1)
        {
            filelink->copyFileToDate(pic_date,CARIN,Camera_picIn);
            res=this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picIn,carNum,pic_date);
        }
        break;
    default:
        break;
    }
    timer_update->start(3000);
}


void MainWindow::bzeroInfo(displayData_t &info) //初始化语音 屏幕信息
{
    info.audioStr.clear();
    int j;
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
}
void MainWindow::makeAudio(displayData_t &info) //合成语音
{
    int i=0;
    for(i=1;i<4;i++)
    {
        if(!info.DispelayStr[i].isEmpty())
            info.audioStr.append(info.DispelayStr[i].trimmed());
    }
}
void MainWindow::carNumberOut_Slot(QString carNum, QPixmap *pic)  //出口抓拍
{
    bool res;
    displayData_t info;
    int j;
    info.audioStr.clear();
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    this->outPixmap = *pic;
    if(sysInfo->savePicture==1)
    {
        pic->save(QString("out.jpg"),"JPG");
    }
    QDateTime time = QDateTime::currentDateTime();
    QString pound_no = time.toString("yyyy-MM-dd-hh-mm-ss-zzz");
    Camera_picOut=pound_no+"2"+".bmp";
    QString pic_date=time.toString("yyyyMMdd");
    ui->label_picture_out->setPixmap(this->outPixmap);
    //carNum="晋APR356";
    if(!carNumberOut_flag)
    {
        return;
    }
    ui->pushButton_carOut->setText(carNum);
    if(sysInfo->cameraOutIp.isEmpty())
    {
        return;
    }
    if(carNum.isEmpty())
    {
        if(IcCardNum.isEmpty())
        {
            info.audioStr ="车牌未识别请倒车重新识别  ";
            info.DispelayStr[3] = info.audioStr;
            this->cameraOut->socket_short_display(&info);

            if(sysInfo->savePicture==1)
            {
                //filelink->copyFile(DIRTEMP,CAROUT,Camera_picOut);
                filelink->copyFileToDate(pic_date,CAROUT,Camera_picOut);
                res=this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picOut,carNum,pic_date);
            }
            timer_update2->start(10000);
            return;
        }else{
            carNum= IcCardNum;
            ui->pushButton_carOut->setText(carNum);
        }
    }

    Car_OutVehicle=carNum;
    //ui->pushButton_open_in->setText(CAR_SEAT);
    if(sysInfo->passFlag==1)
    {
        int car_res;
        car_res=showMap(carNum,"出");
        if(car_res==1)
        {
            qDebug()<<carNum;
        }else if(car_res==0)
        {
            car_map[carNum] = Carployee("出",QDateTime::currentDateTime());
        }
        else if(car_res==2){
            info.audioStr=QString("请%1秒后重新识别").arg(pass_flag_heart);
            info.DispelayStr[3] = info.audioStr;
            this->cameraOut->socket_short_display(&info);
            timer_update2->start(10000); ///启动还原屏幕信息函数
            return;
        }
    }
    Car_OutInfor.image_name=Camera_picOut;
    ticketCheck_t carInfo,carInfo1;
    switch(sysInfo->model)
    {
    case 1 :
        res=this->myDb->car_chek(&this->myDb->sqlite_db,&carInfo,QString::number(sysInfo->vehicleFlag),carNum);
        if(res)
        {
            timer_update2->stop();
            if(carInfo.ticketReturn=="nomal")//固定车
            {
                ui->pushButton_carOut->setText(carInfo.car_type+QString(" ")+carNum);
                //显示屏及语音提示
                bool ren;
                //QString sendauto=carNum+QString("请通行");
                info.DispelayStr[1]="固定车";
                info.DispelayStr[2]=carNum;
                info.DispelayStr[3]="一路平安请出场  ";
                int i=0;
                for(i=1;i<4;i++)
                    info.audioStr.append(info.DispelayStr[i]);

                this->cameraOut->socket_short_display(&info);
                timer_out->start(300);
                if(sysInfo->savePicture==1)
                {
                    filelink->copyFileToDate(pic_date,CAROUT,Camera_picOut);
                    this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picOut,carNum,pic_date);
                }

                ren=this->myDb->CarOutInfo(&this->myDb->sqlite_db_bei,carNum,&Car_OutInfor);
                if(ren)
                {
                    res=this->myDb->writeCarOutLog(&this->myDb->sqlite_db_bei,Camera_picOut,"0",&Car_OutInfor);
                    if(res){
                        qDebug()<<"writeCarOutLog true";
                    }else{
                        qDebug()<<"writeCarOutLog false";
                        //this->myDb->writeCarOutLog(&this->myDb->sqlite_db_bei,Camera_picOut,"0",&Car_OutInfor);
                    }
                }
            info_upLink();
            }else{//临时车
                info.audioStr = QObject::tr("临时车").append(carNum).append("禁止通行");
                info.DispelayStr[3] = info.audioStr;
                this->cameraIn->socket_short_display(&info);
                makeAudio(info);
            }

        }
        else{//临时车
            info.audioStr = QObject::tr("临时车").append(carNum).append("禁止通行");
            info.DispelayStr[3] = info.audioStr;
            this->cameraIn->socket_short_display(&info);
            makeAudio(info);
        }
        break;
    case 2:
        my_network->carOut(carNum,Camera_picOut,QString::number(sysInfo->vehicleFlag));
        if(sysInfo->savePicture==1)
        {
            filelink->copyFileToDate(pic_date,CAROUT,Camera_picOut);
            res=this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picOut,carNum,pic_date);
        }
        break;
    case 3:
        res=this->myDb->car_chek(&this->myDb->sqlite_db,&carInfo1,QString::number(sysInfo->vehicleFlag),carNum);
        if(res)
        {
            timer_update2->stop();
            if(carInfo1.ticketReturn=="nomal")//固定车
            {
                ui->pushButton_carOut->setText(carInfo1.car_type+QString(" ")+carNum);
                bzeroInfo(info);

                info.DispelayStr[1]="固定车";
                info.DispelayStr[2]=carNum;
                info.DispelayStr[3]="一路平安请出场 ";
                makeAudio(info);
                this->cameraOut->socket_short_display(&info);
                timer_out->start(260);
                bool nes;
                nes=this->myDb->CarOutInfo(&this->myDb->sqlite_db_bei,QString::number(sysInfo->vehicleFlag),carNum,&Car_OutInfor);
                if(nes){
                    res=this->myDb->writeCarOutLog(&this->myDb->sqlite_db_bei,Camera_picOut,"0",&Car_OutInfor);
                    if(sysInfo->savePicture==1){
                        filelink->copyFileToDate(pic_date,CAROUT,Camera_picOut);
                        this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picOut,carNum,pic_date);
                    }
                }
                //上传车辆通行记录
                info_upLink();
            }else{
                ui->pushButton_carOut->setText(QString("临时车 ")+carNum);
                info.DispelayStr[1]=" 临时车 ";
                info.DispelayStr[2]=carNum;
                info.DispelayStr[3]=carInfo1.ticketReturn;
                makeAudio(info);
                this->cameraOut->socket_short_display(&info);
            }
        }else{
            ui->pushButton_carOut->setText(QString("临时车 ")+carNum);
            info.DispelayStr[1]=" 临时车 ";
            info.DispelayStr[2]=carNum;
            info.DispelayStr[3]="禁止通行 ";
            makeAudio(info);
            this->cameraOut->socket_short_display(&info);
        }
        break;
    case 4:
        my_network->carOut(carNum,Camera_picOut,QString::number(sysInfo->vehicleFlag));
        if(sysInfo->savePicture==1)
        {
            filelink->copyFileToDate(pic_date,CAROUT,Camera_picOut);
            res=this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picOut,carNum,pic_date);
        }
        break;
    default:
        break;
    }
    timer_update2->start(10000);
}

void MainWindow::write_back_in(QDateTime myTime)
{
    LinkInTime=myTime;
    timer_receive->stop();
    timer_receive->start(30000);
    //qDebug()<<"MyLinkInTime"<<myTime.toString("yy-MM-dd hh:mm:ss");
}

void MainWindow::write_back_out(QDateTime myTime)
{
    LinkOutTime=myTime;
    timer2_receive->stop();
    timer2_receive->start(30000);
    //qDebug()<<"MyLinkOutTime"<<myTime.toString("yy-MM-dd hh:mm:ss");
}

void MainWindow::reason_show()
{
    if(sysInfo->model!=3)
    {
        my_network->HandReason();
    }
}

void MainWindow::CarInfinishedSlot(QNetworkReply *reply)//入口通行返回
{
    carMessage carInfor;
    displayData_t info;
    ///bzero(&info,sizeof(info));
    int j;
    info.audioStr.clear();
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    ticketCheck_t carInfo1;
    bool res;
    res=my_network->generalWebIn(reply,&carInfor);
    if(res)
    {
        timer_update->stop();

        ui->pushButton_carIn->setText(carInfor.carFlag+QString(" ")+Car_InVehicle);
        if(carInfor.carFlag=="临时车")
        {
            qDebug()<<"CarInfinishedSlot"<<CAR_SEAT<<sysInfo->park_type;
            if(CAR_SEAT==0 && sysInfo->park_type==4)
            {
                info.DispelayStr[3]=info.audioStr="车位已满禁止进入  ";
                this->cameraIn->socket_short_display(&info);
                return;
            }else{
                info.DispelayStr[1]="临时车";
                info.DispelayStr[2]=Car_InVehicle;
                if(sysInfo->tempCarIn==0)
                {
                    info.DispelayStr[3]=QString("禁止通行 ");
                }else{
                    if( sysInfo->park_type==4)
                    {
                        info.DispelayStr[3]=QString("空位")+CAR_SEAT+QString("个");
                    }//info.DispelayStr[3]=carInfor.carAuto;
                }
                int i=0;
                for(i=1;i<4;i++)
                    info.audioStr.append(info.DispelayStr[i]);

                this->cameraIn->socket_short_display(&info);
                if(sysInfo->park_camera==1 || sysInfo->park_camera==3 || sysInfo->park_camera==5)
                {
                    timer_in->start(300);
                }
            }
            timer_update->start(10000);
        }else{
            info.DispelayStr[3]=info.audioStr=carInfor.carFlag+carInfor.carAuto;
            this->cameraIn->socket_short_display(&info);
            timer_in->start(300);
        }
    }else{
        if(sysInfo->model==2 && carInfor.carRef=="ERROR")
        {
            bool mes;
            QString carNum=Car_InVehicle;
            mes=this->myDb->car_chek(&this->myDb->sqlite_db,&carInfo1,QString::number(sysInfo->vehicleFlag),carNum);
            if(mes)
            {
                ui->pushButton_carIn->setText(carInfo1.car_type+QString(" ")+Car_InVehicle);
                timer_update->stop();
                if(carInfo1.ticketReturn=="nomal")
                {
                    //显示屏及语音提示
                    info.DispelayStr[1]="固定车";
                    info.DispelayStr[2]=carNum;
                    info.DispelayStr[3]="请通行";
                    int i=0;
                    for(i=1;i<4;i++)
                        info.audioStr.append(info.DispelayStr[i]);

                    this->cameraIn->socket_short_display(&info);
                    timer_in->start(300);

                    if(sysInfo->savePicture==1)
                    {
                        QString Pic_date=QDate::currentDate().toString("yyyyMMdd");
                        filelink->copyFileToDate(Pic_date,CARIN,Camera_picIn);
                        this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picIn,carNum,Pic_date);
                    }
                }else{
                    info.DispelayStr[3]=info.audioStr="车牌未识别请倒车重新识别";
                    this->cameraIn->socket_short_display(&info);

                }
            }else{
                ui->pushButton_carIn->setText(QString("临时车 ")+Car_InVehicle);
                timer_update->stop();
                if(sysInfo->tempCarIn==0)
                {
                    info.DispelayStr[1]="临时车";
                    info.DispelayStr[2]=carNum;
                    info.DispelayStr[3]="禁止通行";
                    int i=0;
                    for(i=1;i<4;i++)
                        info.audioStr.append(info.DispelayStr[i]);
                    this->cameraIn->socket_short_display(&info);
                }
                info.DispelayStr[1]="临时车";
                info.DispelayStr[2]=carNum;
                int i=0;
                for(i=1;i<4;i++)
                    info.audioStr.append(info.DispelayStr[i]);
                this->cameraIn->socket_short_display(&info);
                //my_network->carIn(carNum,Camera_picIn);
                timer_update->start(10000);
            }
        }else{
            timer_update->stop();
            QString car_num=Car_InVehicle;
            qDebug()<<"MainWindow::CarInfinishedSlot(QNetworkReply *reply)"<<sysInfo->tempCarIn;
            if(!carInfor.carAuto.isEmpty())
            {
                info.DispelayStr[3]=info.audioStr=carInfor.carAuto;
                this->cameraIn->socket_short_display(&info);
            }else{
                if(carInfor.carRef.isEmpty())
                {
                    //emit send_serIP_change();
                }
                info.DispelayStr[2]=car_num;
                info.DispelayStr[3]="服务器连接异常无法入场";
                int i=0;
                for(i=1;i<4;i++)
                    info.audioStr.append(info.DispelayStr[i]);
                this->cameraIn->socket_short_display(&info);
            }
            timer_update->start(5000);
        }
    }

}

void MainWindow::CarOutfinishedSlot2(QNetworkReply *reply)//出口通行返回
{
    carMessage carOutfor;
    displayData_t info;
    ///bzero(&info,sizeof(info));
    int j;
    info.audioStr.clear();
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    ticketCheck_t carInfo;
    bool res;
    res=my_network->generalWebOut(reply,&carOutfor);
    if(res)
    {
        Car_OutInfor.pass_num=carOutfor.pass_no;
        Car_OutInfor.parkTime=carOutfor.carParktime;
        Car_OutInfor.endTime=carOutfor.carOuttime;
        Car_OutInfor.money=carOutfor.carFee.toDouble();
        Car_OutInfor.parked_time=carOutfor.parked_time;

        timer_update2->stop();
        ui->lcdNumber->display(carOutfor.carFee);
        ui->label_parkTime->setText(carOutfor.carParktime);
        ui->label_beginT->setText(carOutfor.carIntime);
        ui->label_endT->setText(carOutfor.carOuttime);
        ui->pushButton_carOut->setText(carOutfor.carFlag+QString(" ")+Car_OutVehicle);
        if(carOutfor.carFlag == "固定车")
        {
            info.DispelayStr[3]=info.audioStr=carOutfor.carFlag+carOutfor.carAuto;
            this->cameraOut->socket_short_display(&info);
            timer_out->start(300);
        }else{
            Money_Auto(carOutfor.carParktime,carOutfor.carFee);
            if(ui->lcdNumber->value()==0)
            {
                if(sysInfo->park_camera==1 || sysInfo->park_camera==4 || sysInfo->park_camera==5)
                {
                    timer_out->start(300);
                }
            }else{
                timer_update2->start(30000);
            }
        }
    }else{
        if(sysInfo->model==2 && carOutfor.carRef=="ERROR")
        {
            //QString carNum=ui->pushButton_carOut->text();
            QString carNum=Car_OutVehicle;
            res=this->myDb->car_chek(&this->myDb->sqlite_db,&carInfo,QString::number(sysInfo->vehicleFlag),carNum);
            if(res)
            {
                ui->pushButton_carOut->setText(carInfo.car_type+QString(" ")+Car_OutVehicle);
                timer_update2->stop();
                if(carInfo.ticketReturn=="nomal")
                {
                    //显示屏及语音提示
                    info.DispelayStr[1]=" 固定车 ";
                    info.DispelayStr[2]=carNum;
                    info.DispelayStr[3]="请通行";
                    int i=0;
                    for(i=1;i<4;i++)
                        info.audioStr.append(info.DispelayStr[i]);
                    this->cameraOut->socket_short_display(&info);
                    timer_out->start(300);
                    if(sysInfo->savePicture==1)
                    {
                        QString Pic_date=QDate::currentDate().toString("yyyyMMdd");
                        filelink->copyFileToDate(Pic_date,CAROUT,Camera_picOut);
                        this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picOut,carNum,Pic_date);
                    }
                }else{
                    info.DispelayStr[3]=info.audioStr=carInfo.ticketReturn;
                    this->cameraOut->socket_short_display(&info);
                    timer_update2->start(20000);
                }
            }else{
                ui->pushButton_carOut->setText(QString("临时车 ")+Car_OutVehicle);
                if(sysInfo->tempCarIn==0)
                {
                    info.DispelayStr[1]="临时车";
                    info.DispelayStr[2]=carNum;
                    info.DispelayStr[3]="禁止通行";
                    int i=0;
                    for(i=1;i<4;i++)
                        info.audioStr.append(info.DispelayStr[i]);
                    this->cameraOut->socket_short_display(&info);
                    timer_update2->start(10000);
                }else{
                    bool ren;
                    ren=this->myDb->CarOutInfo(&this->myDb->sqlite_db,QString::number(sysInfo->vehicleFlag),carNum,&Car_OutInfor);
                    if(ren)
                    {
                        ui->label_parkTime->setText(Car_OutInfor.parkTime);
                        ui->label_beginT->setText(Car_OutInfor.beginTime.mid(5,11));
                        ui->label_endT->setText(Car_OutInfor.endTime.mid(5,11));
                        ui->lcdNumber->display(Car_OutInfor.money);
                        QString car_ourtnum;
                        car_ourtnum=carNum;

                        info.DispelayStr[1]="临时车";
                        info.DispelayStr[2]=carNum;
                        info.DispelayStr[3].append("收费").append(QString::number(Car_OutInfor.money)).append("元");
                        int i=0;
                        for(i=1;i<4;i++)
                            info.audioStr.append(info.DispelayStr[i]);
                        this->cameraOut->socket_short_display(&info);
                    }else
                    {
                        info.DispelayStr[2]=info.audioStr=carNum;
                        this->cameraOut->socket_short_display(&info);
                    }
                    timer_update2->start(60000);
                }
            }
        }else{
            timer_update2->stop();
            if(!carOutfor.carAuto.isEmpty())
            {
                CarOutError=carOutfor.carAuto;
                info.DispelayStr[3]=info.audioStr=Car_OutVehicle+carOutfor.carAuto;
                this->cameraOut->socket_short_display(&info);
                if(sysInfo->park_camera==1)
                {
                    timer_in->start(300);
                }
            }else{
                if(carOutfor.carRef.isEmpty())
                {
                    //emit send_serIP_change();
                }
                info.DispelayStr[3]=info.audioStr=Car_OutVehicle+QString("网络连接异常无入场信息");
                this->cameraOut->socket_short_display(&info);
                if(sysInfo->park_camera==1)
                {
                    timer_in->start(300);
                }
            }
            timer_update2->start(20000);
        }
    }
    put_recordInOut();
}

void MainWindow::Money_Auto(QString park_time,QString num)
{
    displayData_t info;
    ///bzero(&info,sizeof(info));
    int j;
    info.audioStr.clear();
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    QString sendauto=QString("停车").append(park_time).append(QString("收费")).append(num).append(QString("元"));
    //QByteArray sendArray;
    //sendArray = gb2312->fromUnicode(sendauto);
    info.DispelayStr[3]=info.audioStr=sendauto;
    this->cameraOut->socket_short_display(&info);
    carNumberOut_flag=false;
    timer_quit_carNumberOut->start(CAMERA_OFF_TIMER);
}

void MainWindow::ReasonfinishedSlot(QNetworkReply *reply)
{
    my_network->generalWebHand(reply);//获取手动出场原因
    qDebug()<<"ReasonfinishedSlot";
    if(sysInfo->first_down==1)
    {
        put_firstcar();
    }else{
        down_car();
    }
}

void MainWindow::TimefinishedSlot(QNetworkReply *reply)//获取时间
{
    carMessage carOutfor;
    displayData_t info;
    ///bzero(&info,sizeof(info));
    int j;
    info.audioStr.clear();
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    bool res;
    res=my_network->generalWebTime(reply,&carOutfor);
    qDebug()<<"TimefinishedSlot"<<res;
    if(res)
    {
        //QByteArray sendArray;
        //sendArray = gb2312->fromUnicode(carOutfor.curTime);
        //  info.DispelayStr[3]=info.audioStr=carOutfor.curTime;
        if(!sysInfo->cameraInIp.isEmpty())
        {
            this->cameraIn->socket_short_display(&info);
        }
        if(!sysInfo->cameraOutIp.isEmpty())
        {
            this->cameraIn->socket_short_display(&info);
        }
    }
    //网络获取手动原因
    reason_show();
}

void MainWindow::RemainfinishedSlot(QNetworkReply *reply)//获取剩余车位
{
    carMessage carOutfor;
    bool res;

    res=my_network->generalWebRemain(reply,&carOutfor);
    if(res)
    {
        CAR_SEAT=carOutfor.curTime;
    }
}

void MainWindow::CarFirstSlot(QNetworkReply *reply)//第一次获取固定车
{
    //    bool res;
    //   res=my_network->generalWebCarFirst(reply);
    //    qDebug()<<"CarFirstSlot"<<res;
    //    if(res)
    //    {
    //      udpLink->first_down_reset();
    down_car();
    //    }
}

void MainWindow::TempImagesSlot(QNetworkReply *reply)//本地图片上传返回
{
    bool res;
    carMessage carInfor;
    res=my_network->generalWebTempImage(reply,&carInfor);
    qDebug()<<"TempImagesSlot"<<res;
    if(res)
    {
        QString hand_res;
        hand_res=this->myDb->hand_InImage(&this->myDb->sqlite_db,carInfor.carVehicle);
        if(hand_res!="null")
        {
            QString hand_res;
            hand_res=this->myDb->hand_InImage(&this->myDb->sqlite_db,carInfor.carVehicle);
            if(hand_res!="null")
            {
                this->myDb->inOutimage_move(&this->myDb->sqlite_db,carInfor.carVehicle);
                filelink->MoveMyFile(hand_res,carInfor.carVehicle);
            }
        }
        put_image();
    }
}

void MainWindow::HandfinishedSlot3(QNetworkReply *reply)//手动起杠
{
    carMessage carInfor;//手动起杠
    bool res;
    res=my_network->generalWebHandOpen(reply,&carInfor);
    if(res)
    {
        qDebug()<<"HandfinishedSlot3"<<carInfor.carRef<<carInfor.carAuto;
    }
}

void MainWindow::CarfinishedSlot4(QNetworkReply *reply)//web下载固定车信息返回
{
    carMessage carInfor;
    my_network->generalWebCarMessage(reply,&carInfor);
}

void MainWindow::InOutfinishedSlot5(QNetworkReply *reply)//web上传通行记录返回
{
//    web_record_in_out info_record;
//    my_network->generalWebInOutup(reply,info_record);
}

void MainWindow::InOutfinishedSlot6(QNetworkReply *reply)//web下载通行记录返回
{
    QString time;
    time=this->myDb->select_updateTime_record(&this->myDb->sqlite_db_bei);
    my_network->generalWebInOutdown(reply,time);
}

void MainWindow::carbindfinishedSlot(QNetworkReply *reply)
{
    my_network->generalWebcarbinddown(reply);
}

void MainWindow::carstallfinishedSlot(QNetworkReply *reply)
{
    my_network->generalWebcarstalldown(reply);
}

void MainWindow::dataBaseLink()
{
    timer_dataBaseLink->stop();
    if(mysql_link->mySql_db.isOpen())
    {
        this->mysql_link->start();
        timer_dataBaseLink->start(300*60000);
        qDebug()<<"mySqldb success";
    }
    else
    {
        this->mysql_link->start();
        qDebug()<<"mySqldb faile";
        timer_dataBaseLink->start(60000);
    }
}

void MainWindow::CameraInRecive()
{
    emit send_cameraIn(sysInfo->cameraInIp);
}

void MainWindow::CameraOutRecive()
{
    emit send_cameraOut(sysInfo->cameraOutIp);
}

void MainWindow::car_inClear()
{
    timer_carIn->stop();
    Car_InVehicle.clear();
    ui->pushButton_carIn->setText("");
}

void MainWindow::car_outClear()
{
    timer_carOut->stop();
    Car_OutVehicle.clear();
}

void MainWindow::Car_downLink()
{
    timer_CarDown->stop();
    this->down_network->start();
    timer_CarDown->start(20000);
}
//下载车辆通行记录
void MainWindow::info_downLink()
{
    //qDebug()<<"=====下载车辆通行记录info_downLink()Start=====";
    timer_recordDown->stop();
    QString max_updated_at;
    max_updated_at=this->myDb->select_updateTime_record(&this->myDb->sqlite_db_bei);
    my_network->WebPost_InOutRecorddownload(max_updated_at);
    //this->myDb->update_lasttime_record(&this->myDb->sqlite_db_bei,lasttime);
    timer_recordDown->start(60000);
    //qDebug()<<"=====下载车辆通行记录info_downLink()End=======";
}

//下载车辆车位绑定信息
void MainWindow::seatbind_downLink()
{
    //qDebug()<<"=====下载车辆车位绑定信息seatbind_downLink()Start=====";
    timer_bind_down->stop();
    QString max_updated_at;
    max_updated_at=this->myDb->select_updateTime_carbind(&this->myDb->sqlite_db);
    my_network->WebPost_carbind_download(max_updated_at);
    timer_bind_down->start(150000);
    //qDebug()<<"=====下载车辆车位绑定信息seatbind_downLink()End=======";
}

void MainWindow::car_stall_downLink()
{
    //qDebug()<<"=====下载车位信息car_stall_downLink()Start=====";
    timer_stall_down->stop();
    QString max_updated_at;
    max_updated_at=this->myDb->select_updateTime_carstall(&this->myDb->sqlite_db);
    //qDebug()<<"WebPost==MainWindow::car_stall_download -max_updated_at"<<max_updated_at;
    my_network->WebPost_car_stall_download(max_updated_at);
    timer_stall_down->start(300000);
   // qDebug()<<"=====下载车位信息car_stall_downLink()End=======";
}
//上传车辆通行记录
void MainWindow::info_upLink()
{
    // qDebug()<<"=====上传车辆通行记录info_upLink()Start=====";
    timer_recordup->stop();
    ticketCheck_t checkinfo;
    web_record_in_out record1;
    QByteArray mybaty;
    record1=this->myDb->select_inout_record(&this->myDb->sqlite_db_bei,record1);
    if(record1.car_no ==" ")
    {
        //qDebug()<<"无上传通行记录";
        timer_recordup->start(30000);
        // qDebug()<<"=====上传车辆通行记录info_upLink()End=======";
        return;
    }
    checkinfo.car_no=record1.car_no;
    checkinfo.status=record1.status;
    checkinfo.inImage=record1.in_image;
    checkinfo.outImage=record1.out_image;
    bool res=this->myDb->inOutimage_selcet(&this->myDb->sqlite_db,&checkinfo);
    if(res)
    {
        mybaty= filelink->openMyDateFile(checkinfo.dirflag,checkinfo.ticketReturn);
        if(mybaty.isEmpty())
        {
            this->myDb->inOutimage_move(&this->myDb->sqlite_db,checkinfo.ticketReturn);
        }
       // qDebug()<<"上传通行记录有图"<<checkinfo.car_no;
        my_network->WebPost_InOutRecordupload(record1,mybaty);
    }else{
        mybaty.clear();
       // qDebug()<<"上传通行记录无图"<<checkinfo.car_no;
        my_network->WebPost_InOutRecordupload(record1,mybaty);
    }
    timer_recordup->start(30000);
   // qDebug()<<"=====上传车辆通行记录info_upLink()End=======";
}

void MainWindow::Image_putLink()
{
    //time_putimage->stop();
    //Image_link->start();
}
void MainWindow::PutImageProcess(bool mes)
{
   // if(mes)
   // {
        //time_putimage->start(600);
   // }else{
        //time_putimage->start(sysInfo->downTime.toInt()*60000);
   // }
}
void MainWindow::initUdp()
{
    udpLink = new udpSocket(sysInfo);
    //建立UDP链接
    udpLink->udpBroadLink = new QUdpSocket(this);
    udpLink->udpBroadLink->bind(6996,QUdpSocket::ShareAddress);
    udpLink->udp_send();
    connect(udpLink->udpBroadLink,SIGNAL(readyRead()),this,SLOT(udpRecProcess()));
    //链接数据库
    udpLed = new ledTcp();
    qDebug()<<"initUdp";
}

void MainWindow::initFtp()
{

}

void MainWindow::udpRecProcess()
{
    qDebug() << "udpRec";
    udpLink->udp_broadcast_reciver_data();
    if(udpLink->dev_reboot)
    {
        timer_dog->stop();
        char buf[30]="reboot";
        ::system(buf);
    }
}

void MainWindow::on_pushButton_OK_clicked()//收费
{
    /*
    displayData_t info;
    int j;
    info.audioStr.clear();
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }

    if(ui->lcdNumber->value()==0)
    {
        qDebug()<<"return"<<ui->lcdNumber->value();
        return;
    }
    //显示屏及语音提示
    bool res;
    QString car_num=Car_OutVehicle;

    info.DispelayStr[2]=Car_OutVehicle;
    info.DispelayStr[3]="一路平安请出场";
    int i=0;
    for(i=1;i<4;i++)
        info.audioStr.append(info.DispelayStr[i]);
    this->cameraOut->socket_short_display(&info);
    if(sysInfo->model==3)
    {
        if(!Car_OutInfor.pass_num.isEmpty())
        {
            qDebug()<<"out"<<Car_OutInfor.pass_num;
            res=this->myDb->writeCarOutLog(&this->myDb->sqlite_db_bei,Camera_picOut,QString::number(Car_OutInfor.money),&Car_OutInfor);
            if(res)
            {
                ui->label_beginT->clear();
                ui->label_parkTime->clear();
                ui->label_endT->clear();
                ui->lcdNumber->display(0);
            }
            //this->myDb->writeCarOutLog(&this->myDb->sqlite_db_bei,Camera_picOut,QString::number(Car_OutInfor.money),&Car_OutInfor);
        }
    }else{
        my_network->FreeCar(&Car_OutInfor,QString::number(ui->lcdNumber->value()));
        ui->label_beginT->clear();
        ui->label_parkTime->clear();
        ui->label_endT->clear();
        ui->lcdNumber->display(0);
    }
    timer_out->start(200);
    if(sysInfo->savePicture==1)
    {
        //filelink->copyFile(DIRTEMP,CAROUT,Camera_picOut);
        QString Pic_date=QDate::currentDate().toString("yyyyMMdd");
        filelink->copyFileToDate(Pic_date,CAROUT,Camera_picOut);
        this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picOut,car_num,Pic_date);
    }
    */
}

void MainWindow::on_pushButton_open_in_clicked()//入口手动起杠
{
    timer_in->start(200);
    /*
    if(sysInfo->cameraInIp.isEmpty())
    {
        return;
    }
    displayData_t info;
    bzeroInfo(info);
    if(sysInfo->model==3)
    {
        // 显示屏及语音提示
        QString carnum=Car_InVehicle;
        QString car_message=ui->pushButton_carIn->text();
        info.DispelayStr[2]=Car_InVehicle;
        info.DispelayStr[3]="欢迎光临  ";
        int i=0;
        for(i=1;i<4;i++)
        {
            if(!info.DispelayStr[i].isEmpty())
                info.audioStr.append(info.DispelayStr[i]);
        }
        this->cameraIn->socket_short_display(&info);
        //qDebug()<<"**on_pushButton_open_in_clicked**"<<Car_InVehicle<<Car_InVehicle.length()<<car_message<<car_message.right(7);
        qDebug()<<"-----------car_message:---------"<<car_message;
        if(car_message.isEmpty())
        {
            qDebug()<<"手动起杆"<<"-----------------------";
            this->myDb->writeCarInLog(&this->myDb->sqlite_db_bei,"手动起杆",Camera_picIn,"临时车","","已入"," ");
        }else{
            bool nes;
            QString per_address="";
            carnum=car_message.right(7) ;
            nes=this->myDb->updateCarOutLog(&this->myDb->sqlite_db_bei,carnum);
            if(!nes)
            {
                qDebug()<<"----------------ready to write to sql :"<<carnum;
                this->myDb->writeCarInLog(&this->myDb->sqlite_db_bei,carnum,Camera_picIn,"临时车",per_address,"已入"," ");
            }
            ui->pushButton_carIn->setText(QString("临时车 ")+carnum);
        }
        timer_in->start(250);

        if(sysInfo->savePicture==1)
        {
            QString Pic_date=QDate::currentDate().toString("yyyyMMdd");
            filelink->copyFileToDate(Pic_date,CARIN,Camera_picIn);
            this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picIn,carnum,Pic_date);
        }
        return;
    }else{
        qDebug()<<"on_pushButton_open_in_clicked()"<<Car_InVehicle<<sysInfo->tempCarIn;
        if(Car_InVehicle.isEmpty() && sysInfo->tempCarIn==0)
        {
            Reason reason_in(this->myDb);
            reason_in.showFullScreen();
            reason_in.exec();
            if(REASON!="N" && REASONID!="N")
            {
                QString car_no=Car_InVehicle;
                // QByteArray sendArray;
                // sendArray = gb2312->fromUnicode(REASON);
                info.DispelayStr[3]=info.audioStr=REASON;
                this->cameraIn->socket_short_display(&info);
                QString handOpenIn=my_network->HandCroess(car_no,REASON);
                my_network->WebPost_HandIn(handOpenIn);
                timer_in->start(200);
                this->myDb->writeCarInLog(&this->myDb->sqlite_db_bei,"手动起杆",Camera_picIn,"临时车","","已入"," ");
            }
        }else{
            my_network->carTempIn(Car_InVehicle,Camera_picIn);
            info.DispelayStr[3]=info.audioStr="欢迎入场  ";
            this->cameraIn->socket_short_display(&info);
            timer_in->start(250);
            this->myDb->writeCarInLog(&this->myDb->sqlite_db_bei,"手动起杆",Camera_picIn,"临时车","","已入"," ");
        }
        qDebug()<<"in"<<REASON<<REASONID;
    }*/
}

void MainWindow::camera_in() ///入口起杆
{
    timer_in->stop(); ///
    timer_carIn->stop();
    this->cameraIn->socket_short_request_open(REQUEST_OPEN);
    timer_update->start(10000);///
    timer_carIn->start(sysInfo->heart*1000);
    carNumberIn_flag=false;
    timer_quit_carNumberIn->start(CAMERA_OFF_TIMER);
    IcCardNum.clear();
    qDebug()<<"***camera_in***"<<Car_InVehicle<<Car_InVehicle.length();
    if(sysInfo->model!=3)
    {
        QByteArray sendArray;
        QString send_mes;
        send_mes.append("001%1");
        send_mes.append(QString("空位: %1个$$").arg(CAR_SEAT));
        sendArray = gb2312->fromUnicode(send_mes);
        udpLed->socket_led_display(sendArray);
    }

}

void MainWindow::on_pushButton_carIn_clicked()//入口补拍 ///抓拍短链接
{
    if(!sysInfo->cameraInIp.isEmpty())
    {
        this->cameraIn->socket_short_request(REQUEST_TARGET);
    }
}

void MainWindow::on_pushButton_carOut_clicked()//出口补拍  ///抓拍短链接
{
    if(!sysInfo->cameraOutIp.isEmpty())
    {
        this->cameraOut->socket_short_request(REQUEST_TARGET);
    }
}

void MainWindow::on_pushButton_open_out_clicked()//出口手动起杠
{

    if(sysInfo->cameraOutIp.isEmpty())
    {
        return;
    }
    int j;
    displayData_t info;
    info.audioStr.clear();
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    //显示屏及语音提示
    info.DispelayStr[2]=Car_OutVehicle;
    info.DispelayStr[3]="一路平安请出场   ";
    int i=0;
    for(i=1;i<4;i++)
    {
        if(!info.DispelayStr[i].isEmpty())
            info.audioStr.append(info.DispelayStr[i]);
    }
    this->cameraOut->socket_short_display(&info);
    timer_out->start(250);
    /*
    if(sysInfo->cameraOutIp.isEmpty())
    {
        return;
    }
    ///bzero(&info,sizeof(info));
    int j;
    displayData_t info;
    info.audioStr.clear();
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    if(sysInfo->model==3)
    {
        //显示屏及语音提示
        bool res;
        QString carnum=Car_OutVehicle;
        info.DispelayStr[2]=Car_OutVehicle;
        info.DispelayStr[3]="一路平安请出场   ";
        int i=0;
        for(i=1;i<4;i++)
        {
            if(!info.DispelayStr[i].isEmpty())
                info.audioStr.append(info.DispelayStr[i]);
        }
        qDebug()<<"qigan";
        this->cameraOut->socket_short_display(&info);
        if(!Car_OutInfor.pass_num.isEmpty())
        {
            res=this->myDb->writeCarOutLog(&this->myDb->sqlite_db_bei,Camera_picOut,QString::number(Car_OutInfor.money),&Car_OutInfor);
            if(res)
            {
                ui->label_beginT->clear();
                ui->label_parkTime->clear();
                ui->label_endT->clear();
                ui->lcdNumber->display(0);
            }
        }else{
            //this->myDb->writeCarInLog(&this->myDb->sqlite_db_bei,"手动起杆",Camera_picOut,"临时车","","已出");
        }
        timer_out->start(250);
        if(sysInfo->savePicture==1)
        {
            //filelink->copyFile(DIRTEMP,CAROUT,Camera_picOut);
            QString Pic_date=QDate::currentDate().toString("yyyyMMdd");
            filelink->copyFileToDate(Pic_date,CAROUT,Camera_picOut);
            this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picOut,carnum,Pic_date);
        }
        return;
    }else{
        qDebug()<<"on_pushButton_open__clicked()"<<Car_OutInfor.pass_num;
        if(Car_OutInfor.pass_num.isEmpty())
        {
            Reason reason_out(this->myDb);
            reason_out.showFullScreen();
            reason_out.exec();
            if(REASON!="N" && REASONID!="N")
            {
                //QString car_no=ui->pushButton_carOut->text();
                QString car_no=Car_OutVehicle;
                info.DispelayStr[3]=info.audioStr=REASON;
                this->cameraOut->socket_short_display(&info);
                QString handOpenOut=my_network->HandCroess(car_no,REASON);
                my_network->WebPost_HandOut(handOpenOut);
                timer_out->start(200);
                ui->label_beginT->clear();
                ui->label_parkTime->clear();
                ui->label_endT->clear();
                ui->lcdNumber->display(0);
            }
            qDebug()<<"out"<<REASON<<REASONID;
        }else{
            my_network->FreeCar(&Car_OutInfor,QString::number(0));
            info.DispelayStr[3]=info.audioStr=QString("一路平安请出场空位")+CAR_SEAT+QString("个");
            this->cameraOut->socket_short_display(&info);
            timer_out->start(300);
            ui->label_beginT->clear();
            ui->label_parkTime->clear();
            ui->label_endT->clear();
            ui->lcdNumber->display(0);
        }
    }
    */
}

  void MainWindow::camera_out()
 {
    timer_out->stop();
    //this->cameraOut->socket_short_request(REQUEST_OPEN);
    this->cameraOut->socket_short_request_open(REQUEST_OPEN);
    timer_update2->start(10000); ///做修改将出口还原时间函数加入
    timer_carOut->start(sysInfo->heart*1000);
    carNumberOut_flag=false;
    timer_quit_carNumberOut->start(CAMERA_OFF_TIMER);
    Car_OutInfor.pass_num.clear();
    if(!IcCardNum.isEmpty())
    {
        // this->myDb->inOutIc_delete(&this->myDb->sqlite_db,IcCardNum);
        IcCardNum.clear();
    }
    CarOutError.clear();
    if(sysInfo->model!=3)
    {
        QByteArray sendArray;
        QString send_mes;
        send_mes.append("!#001%1");
        send_mes.append(QString("空位: %1个$$").arg(CAR_SEAT));
        // QString send_mes=QString("空位")+CAR_SEAT+QString("个");
        sendArray = gb2312->fromUnicode(send_mes);
        udpLed->socket_led_display(sendArray);
    }
}

void MainWindow::on_pushButton_in_zoom_clicked()
{
    if(!this->inPixmap.isNull())
    {
        scroll= new scrollarea;
        scroll->set_image(&this->inPixmap);
        scroll->show();
    }
}

void MainWindow::on_pushButton_out_zoom_clicked()
{
    if(!this->outPixmap.isNull())
    {
        scroll= new scrollarea;
        scroll->set_image(&this->outPixmap);
        scroll->show();
    }
}

void MainWindow::carupdate_send()
{
   // timer_down->stop();
    /**********下载固定车*******/
    if(sysInfo->model==3)
    {
        return;
    }else{
        //网络发送请求时间
        my_network->GetTime();
        if(sysInfo->updataPicture ==1)
        {
            //time_putimage->start(10000);
        }
    }
}

void MainWindow::put_firstcar()
{
    my_network->FirstDownLoadCar();
}

void MainWindow::down_car()
{
    //QString vechiel="1970-01-01 01:00:00";
    //my_network->DownLoadCar(vechiel);
    //emit send_msg("1970-01-01 01:00:00");
    timer_CarDown->start(5000);
}

void MainWindow::put_recordInOut()
{
    /*******上传通行记录*******/
    timer_recordup->stop();;
    ticketCheck_t checkInfo;
    int res;
    res=this->myDb->send_in_out_record(&this->myDb->sqlite_db_bei,&checkInfo);
    qDebug()<<"ready to put  the recordInOut";
    switch(res)
    {
    case  1:
        //qDebug()<<"case 1 in send_in_out_record  in_out_record"<<checkInfo.ticketReturn<<checkInfo.flag;
        timer_recordup->start(5000);
        break;
    default:
        //qDebug()<<"no record need to up to web";
        break;
    }
}

void MainWindow::put_image()//上传照片
{
    ticketCheck_t checkInfo;
    bool res;
    /*res=this->myDb->inOutimage_selcet(&this->myDb->sqlite_db,&checkInfo);
    if(res)
    {
        if(checkInfo.dirflag=="LOCAL")
        {
            QByteArray mybaty= filelink->openMyFile(1,checkInfo.ticketReturn);
            my_network-> tempcarimage(mybaty,checkInfo.ticketReturn);
        }else{
            QByteArray mybaty= filelink->openMyFile(2,checkInfo.ticketReturn);
            my_network-> tempcarimage(mybaty,checkInfo.ticketReturn);
        }
    }else{
        picput_flag=0;
    }*/
    res=this->myDb->inOutimage_selcet(&this->myDb->sqlite_db,&checkInfo);
    if(res)
    {
        //QByteArray mybaty= filelink->openMyFile(checkInfo.dirflag,checkInfo.ticketReturn);
        QByteArray mybaty= filelink->openMyDateFile(checkInfo.dirflag,checkInfo.ticketReturn);
        my_network-> tempcarimage(mybaty,checkInfo.ticketReturn);
    }else{
        picput_flag=0;
    }
}

void MainWindow::keyPressEvent(QKeyEvent *e)
{
    int a = e->key();
    //qDebug()<<a;
    if(a == 16777221)
    {
        emit send_icnum(QString(ic_cardno));
        ic_cardno.clear();
    }
    else
    {
        ic_cardno.append((char)a);
    }
}

void MainWindow::paintEvent(QPaintEvent *)//背景
{
    QPixmap pix(pic_name);
    QPainter painter(this);
    int w = width();
    int h = height();
    painter.drawPixmap(0,0,w,h,pix);
}

void MainWindow::nextPageHis()
{
    int maxValue = ui->tableWidget->verticalScrollBar()->maximum(); // 当前SCROLLER最大显示值25
    nCurScroller = ui->tableWidget->verticalScrollBar()->value(); //获得当前scroller值

    if(nCurScroller<maxValue)
        ui->tableWidget->verticalScrollBar()->setSliderPosition(pageValue+nCurScroller);
    else
        ui->tableWidget->verticalScrollBar()->setSliderPosition(0);
}
/***上一页***/
void MainWindow::prePageHis()
{
    int maxValue = ui->tableWidget->verticalScrollBar()->maximum(); // 当前SCROLLER最大显示值25
    nCurScroller = ui->tableWidget->verticalScrollBar()->value();

    if(nCurScroller>0)
        ui->tableWidget->verticalScrollBar()->setSliderPosition(nCurScroller-pageValue);
    else
        ui->tableWidget->verticalScrollBar()->setSliderPosition(maxValue);
}

void MainWindow::on_pushButton_up_clicked()
{
    prePageHis();
}

void MainWindow::on_pushButton_down_clicked()
{
    nextPageHis();
}
//更新显示界面
void MainWindow::dispUpdata2()   ////新增函数用于还原出口显示屏时间日期, 空位与disupdata函数入口显示屏相对应
{
    if(sysInfo->model!=3)
    {
        //my_network->GetRemain();
    }
    //当无车无动态消息时，静态显示时间日期静态消息
    displayData_t info;
    ///bzero(&info,sizeof(info));
    int j;
    info.audioStr.clear();
#ifdef OLD_LED
    info.audioStr = "车牌识别  一车一杆  减速慢行";
#endif
    for(j=0;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    info.DispelayStr[0] = "车牌识别  一车一杆  减速慢行";
    info.DispelayStr[1]="\\DL月\\DD日";
    info.DispelayStr[2] ="\\DH时\\DM分";

    if(sysInfo->park_type==4)
    {
        info.DispelayStr[3]=QString("空余车位%1个").arg(CAR_SEAT);
    }else{
        info.DispelayStr[3]=sysInfo->galleryName+"   ";
    }
    //info.DispelayStr[3]=QString("空余车位%1个").arg(CAR_SEAT);
    this->cameraOut->socket_short_display(&info);
    timer_update2->stop();
    map_carLink();
    //显示系统时间
    //  receive_cuTime(QTime::currentTime());//定时删除过期车辆 信息
}

void MainWindow::dispUpdata()
{
    if(sysInfo->model!=3)
    {
        //my_network->GetRemain();
    }
    //当无车无动态消息时，静态显示时间日期静态消息
    displayData_t info;
    int j;
    info.audioStr.clear();
#ifdef OLD_LED
    info.audioStr = "车牌识别  一车一杆  减速慢行";
#endif
    for(j=0;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    info.DispelayStr[0] = "车牌识别  一车一杆  减速慢行";
    info.DispelayStr[1]="\\DL月\\DD日";
    info.DispelayStr[2] ="\\DH时\\DM分";
    //info.DispelayStr[3]=QString("空余车位%1个").arg(CAR_SEAT);

    if(sysInfo->park_type==4)
    {
        info.DispelayStr[3]=QString("空余车位%1个").arg(CAR_SEAT);
    }else{
        info.DispelayStr[3]=sysInfo->galleryName+"   ";
    }
    this->cameraIn->socket_short_display(&info);
    timer_update->stop();
    map_carLink();
    //显示系统时间
    // receive_cuTime(QTime::currentTime());//定时删除过期车辆 信息
}

void MainWindow::disPaint()
{
    ui->lcdNumber_2->display(QDateTime::currentDateTime().toString("MM-dd hh:mm"));
    //显示系统时间
    if(time_flag)
    {
        ui->lcdNumber_2->setStyleSheet("color:green;");
        time_flag=false;

    }else{
        ui->lcdNumber_2->setStyleSheet("color:red;");
        time_flag=true;
       // receive_cuTime(QTime::currentTime());
    }
}

void MainWindow::receive_cuTime(QTime curretTime)
{
//    int secM;
//    secM= curretTime.secsTo(sysInfo->updataTime);
//    if(secM >0 && secM<60)
//    {
//        /*******上传临时车图片*******/
//        if(sysInfo->updataPicture==1 && picput_flag==0)
//        {
//            put_image();
//            qDebug()<<"********put_image*********";
//            picput_flag=1;
//            char cmd[100];
//            QString sevr=sysInfo->serverIp;
//            sprintf(cmd,"/bin/ntpdate %s",sevr.toLatin1().data());
//            system(cmd);
//        }
//        if(sysInfo->savePicture==1)
//        {
//            imagedir_remove();
//        }
//    }else{
//        picput_flag=0;
//    }
    //qDebug()<<"receive_cuTime"<<secM<<secM/60<<curretTime.toString("hh:mm:ss")<<sysInfo->updataTime.toString("hh:mm:ss");
}

QString MainWindow::Date_cureent(QString E_Date)
{
    QString C_Date;
    if(E_Date=="Monday")
    {
        C_Date="星期一";
    }else  if(E_Date=="Tuesday")
    {
        C_Date="星期二";
    }else  if(E_Date=="Wednesday")
    {
        C_Date="星期三";
    }else  if(E_Date=="Thursday")
    {
        C_Date="星期四";
    }else  if(E_Date=="Friday")
    {
        C_Date="星期五";
    }else  if(E_Date=="Saturday")
    {
        C_Date="星期六";
    }else  if(E_Date=="Sunday")
    {
        C_Date="星期日";
    }
    return  C_Date;
}

void MainWindow::ftp_put_pic(int flag,QString pic_name)
{
//    char buf[100];
//    if(flag==1)
//    {
//        char aa[30]="in";
//        sprintf(buf,"ftpput %s ./%s/%s.jpg %s.jpg -u %s -p %s -P%d","192.168.10.16","/qt",pic_name.toLatin1().data(),aa,"xiao","123456",21);
//    }else if(flag==2)
//    {
//        char bb[30]="out";
//        sprintf(buf,"ftpput %s %s.jpg %s.jpg -u %s -p %s -P%d","192.168.10.16",bb,pic_name.toLatin1().data(),"xiao","123456",21);
//    }
//    ::system(buf);
}
void MainWindow::com1RecProcess()
{
    bool res;
    displayData_t info;
    ///bzero(&info,sizeof(info));
    int j;
    info.audioStr.clear();
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    ticketCheck_t ticket;
    res = scanInDev->generalDevRecProcess(ticketDevInfo->comDev[0].com_model);
    if(res)
    {
        ticket.ic_sn= scanInDev->strId;
        res=this->myDb->SqliteDbCheck(&this->myDb->sqlite_db,&ticket);
        if(res)
        {
            //            QByteArray sendArray;
            //          sendArray = gb2312->fromUnicode(ticket.ticketReturn);
            info.DispelayStr[3]=info.audioStr=ticket.ticketReturn;
            this->cameraIn->socket_short_display(&info);
            timer_in->start(200);

        }else{
            //            QByteArray sendArray;
            // sendArray = gb2312->fromUnicode(ticket.ticketReturn);
            info.DispelayStr[3]=info.audioStr=ticket.ticketReturn;
            this->cameraIn->socket_short_display(&info);
        }
    }
}

void MainWindow::com2RecProcess()
{
    switch(ticketDevInfo->comDev[1].com_type)
    {
    case 1:
        break;
    case 2:
        break;
    }
}

void MainWindow::icRecProcess(QString card_num)
{
    bool ren;
    qDebug()<<"ic_num:"<<card_num;
    IcCardNum=card_num;
    ren=this->myDb->CarOutInfo(&this->myDb->sqlite_db,QString::number(1),card_num,&Car_OutInfor);
    if(ren)
    {
        ui->pushButton_carOut->setText(QDateTime::currentDateTime().toString("zzz"));
    }else{
        ui->pushButton_carIn->setText(QDateTime::currentDateTime().toString("zzz"));
    }
}

void MainWindow::CarDownProcess(QString max_updated_at)
{
    qDebug()<<"CarDownProcess"<<max_updated_at;
    if(max_updated_at!="")
    {
        emit send_msg(max_updated_at);
        //qDebug()<<"send------";
        timer_CarDown->start(6000);
    }else{
        emit send_msg("1970-01-01 01:00:00");
        //timer_CarDown->start(sysInfo->downTime.toInt()*60000);
        timer_CarDown->start(6000);
    }
}

/*void MainWindow::on_pushButton_turnclass_clicked()
{
    //car_inout_show(TurnClassTime);
    //ui->stackedWidget->setCurrentIndex(1);
    screen=QPixmap::grabWindow(QApplication::desktop()->winId());
    screen.save("login.png","png");
}*/

void MainWindow::on_pushButton_turnquit_clicked()
{

    //screen4=QPixmap::grabWindow(QApplication::desktop()->winId());
    //screen4.save("out.png","png");
    ui->stackedWidget->setCurrentIndex(0);
    pic_name="images/pic.png";
    update();
}

void MainWindow::on_pushButton_turnok_clicked()
{
    TurnClassTime=QDateTime::currentDateTime();
    ui->stackedWidget->setCurrentIndex(0);
    pic_name="images/pic.png";
    update();
}

void MainWindow::car_inout_show(QDateTime begintime,QDateTime endtime,QSqlDatabase *db,int park_type) //车辆信息
{
    QString begtimestr=begintime.toString("yyyy-MM-dd hh:mm:ss");
    QString endtimestr=endtime.toString("yyyy-MM-dd hh:mm:ss");
    int ret;
    int car_num;
    float all_fee;
    QSqlQuery query,select_car;
    query= QSqlQuery(*db);
    select_car = QSqlQuery(*db);
    QString str_count,str_car;
    if(sysInfo->model==3)
    {
        if(park_type==1)
        {
            str_count=QObject::trUtf8("select count(*),sum(fee) from record_in_out where out_time between '%1' and '%2' and status='已出'").arg(begtimestr).arg(endtimestr);
            str_car=QObject::trUtf8("select car_no,in_time,out_time,part_time,fee,card_type from record_in_out  where out_time between '%1' and '%2' and status='已出'  order by out_time desc").arg(begtimestr).arg(endtimestr);
        }else  if(park_type==2)
        {
            str_count=QObject::trUtf8("select count(*),sum(fee) from record_in_out where out_time  between '%1' and '%2'  and status='%3' and card_type='%4'").arg(begtimestr).arg(endtimestr).arg(QString("已出")).arg("固定车");
            str_car=QObject::trUtf8("select car_no,in_time,out_time,part_time,fee,card_type from record_in_out  where out_time between '%1' and '%2'  and status='%3' and card_type='%4' order by out_time desc").arg(begtimestr).arg(endtimestr).arg("已出").arg("固定车");
        }else  if(park_type==3)
        {
            str_count=QObject::trUtf8("select count(*),sum(fee) from record_in_out where out_time  between '%1' and '%2'  and status='%3' and card_type='%4'").arg(begtimestr).arg(endtimestr).arg(QString("已出")).arg("临时车");
            str_car=QObject::trUtf8("select car_no,in_time,out_time,part_time,fee,card_type from record_in_out  where out_time between '%1' and '%2'  and status='%3' and card_type='%4' order by out_time desc").arg(begtimestr).arg(endtimestr).arg("已出").arg("临时车");
        }else  if(park_type==4)
        {
            str_count=QObject::trUtf8("select count(*),sum(fee) from record_in_out where out_time between '%1' and '%2'  and status='%3' and card_type='%4'").arg(begtimestr).arg(endtimestr).arg(QString("已出")).arg("特殊车");
            str_car=QObject::trUtf8("select car_no,in_time,out_time,part_time,fee,card_type from record_in_out  where out_time between '%1' and '%2'  and status='%3' and card_type='%4' order by out_time desc").arg(begtimestr).arg(endtimestr).arg("已出").arg("特殊车");
        }else{
            str_count=QObject::tr("select count(*),sum(fee) from record_in_out where out_time between '%1' and '%2'  and status='%3'").arg(begtimestr).arg(endtimestr).arg(QString("已出"));
            str_car=QObject::trUtf8("select car_no,in_time,out_time,part_time,fee,card_type from record_in_out  where out_time between '%1' and '%2' and status='%3'  order by out_time desc").arg(begtimestr).arg(endtimestr).arg("已出");
        }
    }else{
        if(park_type==1)
        {
            str_count=QObject::trUtf8("select count(*),sum(fact_fee) from record_in_out where out_time between '%1' and '%2'  and status='%3'").arg(begtimestr).arg(endtimestr).arg(QString("已出"));
            str_car=QObject::trUtf8("select car_no,in_time,out_time,parked_time,fact_fee,card_type from record_in_out  where out_time between '%1' and '%2'  and status='%3'  order by out_time desc").arg(begtimestr).arg(endtimestr).arg("已出");
        }else  if(park_type==2)
        {
            str_count=QObject::trUtf8("select count(*),sum(fact_fee) from record_in_out where out_time '%1' and '%2'  and status='%3' and card_type='%4'").arg(begtimestr).arg(endtimestr).arg(QString("已出")).arg("固定车");
            str_car=QObject::trUtf8("select car_no,in_time,out_time,parked_time,fact_fee,card_type from record_in_out  where out_time '%1' and '%2'  and status='%3' and card_type='%4' order by out_time desc").arg(begtimestr).arg(endtimestr).arg("已出").arg("固定车");
        }else  if(park_type==3)
        {
            str_count=QObject::trUtf8("select count(*),sum(fact_fee) from record_in_out where out_time '%1' and '%2'  and status='%3' and card_type='%4'").arg(begtimestr).arg(endtimestr).arg(QString("已出")).arg("临时车");
            str_car=QObject::trUtf8("select car_no,in_time,out_time,parked_time,fact_fee,card_type from record_in_out  where out_time '%1' and '%2'  and status='%3' and card_type='%4' order by out_time desc").arg(begtimestr).arg(endtimestr).arg("已出").arg("临时车");
        }else  if(park_type==4)
        {
            str_count=QObject::trUtf8("select count(*),sum(fact_fee) from record_in_out where out_time '%1' and '%2'  and status='%3' and card_type='%4'").arg(begtimestr).arg(endtimestr).arg(QString("已出")).arg("特殊车");
            str_car=QObject::trUtf8("select car_no,in_time,out_time,parked_time,fact_fee,card_type from record_in_out  where out_time '%1' and '%2'  and status='%3' and card_type='%4' order by out_time desc").arg(begtimestr).arg(endtimestr).arg("已出").arg("特殊车");
        }else{
            str_count=QObject::trUtf8("select count(*),sum(fact_fee) from record_in_out where out_time between '%1' and '%2'  and status='%3'").arg(begtimestr).arg(endtimestr).arg(QString("已出"));
            str_car=QObject::trUtf8("select car_no,in_time,out_time,parked_time,fact_fee,card_type from record_in_out  where out_time between '%1' and '%2'  and status='%3' order by out_time desc").arg(begtimestr).arg(endtimestr).arg("已出");
        }
    }
    query.clear();
    query.prepare(str_count);
    query.exec();
    ret = query.next();
    if(ret==1)
    {
        car_num=query.value(0).toInt();
        all_fee=query.value(1).toFloat();

    }else{
        car_num=0 ;
        all_fee=0;
    }
    qDebug()<<"*****"<<begtimestr<<endtimestr<<car_num;
    ui->label_car_cunt->setText(QString("%1").arg(car_num));
    ui->lcdNumber_3->display(all_fee);

    ui->tableWidget->setRowCount(car_num);
    ui->tableWidget->setColumnCount(6);
    QStringList headers;
    headers<<QString::fromUtf8("车号")<<QString::fromUtf8("入场时间")<<QString::fromUtf8("出场时间")<<QString::fromUtf8("停车时长")<<QString::fromUtf8("收费(元)")<<QString::fromUtf8("车类型");
    ui->tableWidget->setHorizontalHeaderLabels(headers);
    ui->tableWidget->setColumnWidth(0,118);
    ui->tableWidget->setColumnWidth(1,145);
    ui->tableWidget->setColumnWidth(2,145);
    ui->tableWidget->setColumnWidth(3,120);
    ui->tableWidget->setColumnWidth(4,90);
    ui->tableWidget->setColumnWidth(5,70);

    select_car.clear();
    select_car.exec(str_car);
    for(int i=0;select_car.next();i++)
    {
        QString car_no=select_car.value(0).toString();
        QString car_in=select_car.value(1).toString().replace(10,1," ").mid(2,14);
        QString car_out=select_car.value(2).toString().replace(10,1," ").mid(2,14);
        QString statu =select_car.value(3).toString();
        QString fee=select_car.value(4).toString();
        QString type=select_car.value(5).toString();

        QString messge;
        if(sysInfo->model==3)
        {
            messge=statu;
        }else{
            messge=this->myDb->get_park_time(statu.toInt()*60);
        }

        ui->tableWidget->setItem(i,0,new QTableWidgetItem(car_no));
        ui->tableWidget->setItem(i,1,new QTableWidgetItem(car_in));
        ui->tableWidget->setItem(i,2,new QTableWidgetItem(car_out));
        ui->tableWidget->setItem(i,3,new QTableWidgetItem(messge));
        ui->tableWidget->setItem(i,4,new QTableWidgetItem(fee));
        //ui->tableWidget->setItem(i,5,new QTableWidgetItem(type));
        if( type!="固定车" )
        {
            QTableWidgetItem *item=new  QTableWidgetItem();
            // item->setBackgroundColor(QColor(0,127,0));
            item->setTextColor(QColor(Qt::red));
            item->setText(type);
            ui->tableWidget->setItem(i,5,item);
            QTableWidgetItem *item2=new  QTableWidgetItem();
            item2->setTextColor(QColor(Qt::red));
            item2->setText(car_no);
            ui->tableWidget->setItem(i,0,item2);
        }else{
            ui->tableWidget->setItem(i,5,new QTableWidgetItem(type));
        }
    }
    ui->stackedWidget->setCurrentIndex(1);
    pic_name="images/picR.jpg";
    update();
}

void MainWindow::on_pushButton_allday_clicked()
{
    //car_inout_show(QDateTime(QDate::currentDate()));
    day_flag=QString("Feeday");
    ui->groupBox->setTitle("查询已出日期（天）");
    ui->stackedWidget->setCurrentIndex(3);
    pic_name="images/picR.jpg";
    update();
}

void MainWindow::on_tool_0Btn_clicked()
{
    ui->lineEdit_day->insert(QString::number(0));
    ui->lcdNumber_day->display(ui->lineEdit_day->text());
}

void MainWindow::on_tool_1Btn_clicked()
{
    ui->lineEdit_day->insert(QString::number(1));
    ui->lcdNumber_day->display(ui->lineEdit_day->text());
}

void MainWindow::on_tool_2Btn_clicked()
{
    ui->lineEdit_day->insert(QString::number(2));
    ui->lcdNumber_day->display(ui->lineEdit_day->text());
}

void MainWindow::on_tool_3Btn_clicked()
{
    ui->lineEdit_day->insert(QString::number(3));
    ui->lcdNumber_day->display(ui->lineEdit_day->text());
}

void MainWindow::on_tool_4Btn_clicked()
{
    ui->lineEdit_day->insert(QString::number(4));
    ui->lcdNumber_day->display(ui->lineEdit_day->text());
}

void MainWindow::on_tool_5Btn_clicked()
{
    ui->lineEdit_day->insert(QString::number(5));
    ui->lcdNumber_day->display(ui->lineEdit_day->text());
}

void MainWindow::on_tool_6Btn_clicked()
{
    ui->lineEdit_day->insert(QString::number(6));
    ui->lcdNumber_day->display(ui->lineEdit_day->text());
}

void MainWindow::on_tool_7Btn_clicked()
{
    ui->lineEdit_day->insert(QString::number(7));
    ui->lcdNumber_day->display(ui->lineEdit_day->text());
}

void MainWindow::on_tool_8Btn_clicked()
{
    ui->lineEdit_day->insert(QString::number(8));
    ui->lcdNumber_day->display(ui->lineEdit_day->text());
}

void MainWindow::on_tool_9Btn_clicked()
{
    ui->lineEdit_day->insert(QString::number(9));
    ui->lcdNumber_day->display(ui->lineEdit_day->text());
}

void MainWindow::on_tool_tBtn_clicked()
{  
    //screen=QPixmap::grabWindow(QApplication::desktop()->winId());
    //screen.save("tui.png","png");
    ui->lineEdit_day->backspace();
    if(ui->lineEdit_day->text().isEmpty())
    {
        ui->lcdNumber_day->display(0);
        return;
    }
    ui->lcdNumber_day->display(ui->lineEdit_day->text());
}

void MainWindow::on_tool_okBtn_clicked()
{   /*
    int secDay=ui->lcdNumber_day->value();
    QDateTime enddate=QDateTime::currentDateTime();
    qDebug()<<"day_flag"<<day_flag<<park_form_flag;
    if(day_flag=="Feeday")//收费
    {
        ui->stackedWidget->setCurrentIndex(1);
        QDateTime my_day,end_day;
        if(sysInfo->model==3)
        {
            if(park_form_flag=="N")
            {
                my_day=QDateTime(QDate::currentDate().addDays(-secDay));
                car_inout_show(my_day,enddate,&this->myDb->sqlite_db_bei,park_type_flag);
                ui->label_turn_begin->setText(my_day.toString("yyyy-MM-dd hh:mm"));
                // ui->label_turn_begin->setText(TurnClassTime.toString("yyyy-MM-dd hh:mm"));
                ui->label_turn_end->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm"));
            }else{
                my_day=QDateTime((QDate::currentDate().addDays(-secDay)),(ui->timeEdit_begin->time()));
                end_day=QDateTime((QDate::currentDate()),(ui->timeEdit_end->time()));
                car_inout_show(my_day,end_day,&this->myDb->sqlite_db_bei,park_type_flag);
                ui->label_turn_begin->setText(my_day.toString("yyyy-MM-dd hh:mm"));
                ui->label_turn_end->setText(end_day.toString("yyyy-MM-dd hh:mm"));
            }
        }else{
            if(this->mysql_link->mySql_db.isOpen())
            {
                if(park_form_flag=="N")
                {
                    my_day=QDateTime(QDate::currentDate().addDays(-secDay));
                    car_inout_show(my_day,enddate,&this->mysql_link->mySql_db,park_type_flag);
                    ui->label_turn_begin->setText(my_day.toString("yyyy-MM-dd hh:mm"));
                    // ui->label_turn_begin->setText(TurnClassTime.toString("yyyy-MM-dd hh:mm"));
                    ui->label_turn_end->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm"));
                }else{
                    my_day=QDateTime((QDate::currentDate().addDays(-secDay)),(ui->timeEdit_begin->time()));
                    end_day=QDateTime((QDate::currentDate()),(ui->timeEdit_end->time()));
                    car_inout_show(my_day,end_day,&this->mysql_link->mySql_db,park_type_flag);
                    ui->label_turn_begin->setText(my_day.toString("yyyy-MM-dd hh:mm"));
                    ui->label_turn_end->setText(end_day.toString("yyyy-MM-dd hh:mm"));
                }
            }else{
                QMessageBox::warning(this, tr("提示"), tr("数据库打开失败"));
                return;
            }
        }
    }else if(day_flag=="Feetime")//收费
    {
        ui->stackedWidget->setCurrentIndex(1);
        QDateTime my_dayT=QDateTime::currentDateTime().addSecs(-secDay*3600);
        if(sysInfo->model==3)
        {
            car_inout_show(my_dayT,enddate,&this->myDb->sqlite_db_bei,park_type_flag);
            ui->label_turn_begin->setText(my_dayT.toString("yyyy-MM-dd hh:mm"));
            //ui->label_turn_begin->setText(TurnClassTime.toString("yyyy-MM-dd hh:mm"));
            ui->label_turn_end->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm"));
        }else{
            if(this->mysql_link->mySql_db.isOpen())
            {
                car_inout_show(my_dayT,enddate,&this->mysql_link->mySql_db,park_type_flag);
                ui->label_turn_begin->setText(my_dayT.toString("yyyy-MM-dd hh:mm"));
                //   ui->label_turn_begin->setText(TurnClassTime.toString("yyyy-MM-dd hh:mm"));
                ui->label_turn_end->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm"));
            }else{
                QMessageBox::warning(this, tr("提示"), tr("数据库打开失败"));
                return;
            }
        }
    }
    else if(day_flag=="day")//已入车辆
    {
        ui->stackedWidget->setCurrentIndex(2);
        if(sysInfo->model==3)
        {
            car_vehicle(QDateTime(QDate::currentDate().addDays(-secDay)),&this->myDb->sqlite_db_bei,park_type_flag);
        }else{
            if(this->mysql_link->mySql_db.isOpen())
            {
                car_vehicle(QDateTime(QDate::currentDate().addDays(-secDay)),&this->mysql_link->mySql_db,park_type_flag);
            }
        }
    }else{
        ui->stackedWidget->setCurrentIndex(2);
        if(sysInfo->model==3)
        {
            car_vehicle(QDateTime::currentDateTime().addSecs(-secDay*3600),&this->myDb->sqlite_db_bei,park_type_flag);
        }else{
            if(this->mysql_link->mySql_db.isOpen())
            {
                // car_vehicle(QDateTime(QDate::currentDate().addDays(-secDay)),&this->mysql_link->mySql_db);
                car_vehicle(QDateTime::currentDateTime().addSecs(-secDay*3600),&this->mysql_link->mySql_db,park_type_flag);
            }
        }
    }
    pic_name="images/picR.jpg";
    update();
    */
}

void MainWindow::on_tool_dBtn_clicked()
{
    ui->lcdNumber_day->display(0);
    ui->lineEdit_day->clear();
}

void MainWindow::closeEvent( QCloseEvent * event )
{
    timer_update->stop();
    //timer_down->stop();
    timer_in->stop();
    timer_out->stop();
    timer_receive->stop();
    timer2_receive->stop();
    timer_carIn->stop();
    timer_carOut->stop();
    timer_CarDown->stop();
    delete  timer_update;
    //delete  timer_down;
    delete timer_in;
    delete timer_out;
    delete timer_receive;
    delete timer2_receive;
    delete   timer_carIn;
    delete  timer_carOut;
    delete  timer_CarDown;
    event->accept();
}

void MainWindow::on_tableWidget_2_clicked(const QModelIndex &index)
{
    hand_carIn=index.sibling(index.row(),0).data().toString();
    QString in_date=index.sibling(index.row(),1).data().toString();
    QString pic_name=index.sibling(index.row(),3).data().toString();
    QString res;
    res=this->myDb->hand_InImage(&this->myDb->sqlite_db,pic_name);
    if(res!="null")
    {
        QString  Lpath=sysInfo->path+"/"+res+"/"+pic_name;
        CarInPicName=Lpath;
        //QByteArray mybaty= filelink->openMyFile(1,pic_name);
        QFile my_infile(Lpath);
        if(my_infile.exists())
        {
            QPixmap aa(Lpath);
            //aa.loadFromData(mybaty,0,Qt::AutoColor);
            ui->label_InImage->setPixmap(aa);
        }else{
            CarInPicName.clear();
            ui->label_InImage->setPixmap(QPixmap("./images/car.jpg"));
        }
    }else{
        if(sysInfo->model==3)
        {
            CarInPicName.clear();
            ui->label_InImage->setPixmap(QPixmap("./images/car.jpg"));
        }else{
            ui->stackedWidget_2->setCurrentIndex(0);
            ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
            ui->webView->setStyleSheet("background-color:rgb(150,147,88); padding: 7px ; color:rgb(255,255,255)");
            QString down_pic=this->my_network->down_picture(in_date.left(10),pic_name);
            QUrl url(down_pic);
            ui->webView->load(url);
        }
    }

    /*QString res;
       res=this->myDb->hand_InImage(&this->myDb->sqlite_db,pic_name);
       qDebug()<<pic_name<<res;
       if(res!="null")
       {
           ui->stackedWidget_2->setCurrentIndex(1);
         //QByteArray mybaty= filelink->openMyFile(1,pic_name);
           QString  Lpath=res+"/"+pic_name;
           CarInPicName=Lpath;
           QFile my_infile(Lpath);
           if(my_infile.exists())
           {
               QPixmap aa(Lpath);
               ui->label_InImage->setPixmap(aa);
           }else{
               ui->label_InImage->setPixmap(QPixmap("./images/car.jpg"));
           }
       }else{
           if(sysInfo->model!=3)
           {
               ui->stackedWidget_2->setCurrentIndex(0);
               ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
               ui->webView->setStyleSheet("background-color:rgb(150,147,88); padding: 7px ; color:rgb(255,255,255)");
               QString down_pic=this->my_network->down_picture(in_date.left(10),pic_name);
               QUrl url(down_pic);
               ui->webView->load(url);
           }
       }*/
}

void MainWindow::on_pushButton_wiget2_back_clicked()
{
    //screen3=QPixmap::grabWindow(QApplication::desktop()->winId());
    //screen3.save("in.png","png");
    ui->stackedWidget->setCurrentIndex(0);
    CarInPicName.clear();
    pic_name="images/pic.png";
    update();
}

void MainWindow::on_pushButton_wiget2_select_clicked()
{
    day_flag=QString("day");
    ui->groupBox->setTitle("查询已入日期（天）");
    ui->stackedWidget->setCurrentIndex(3);
}

void MainWindow::on_pushButton_wiget2_3_clicked()//
{
    if(sysInfo->model==3)
    {
        car_vehicle(QDateTime::currentDateTime().addSecs(-10800),&this->myDb->sqlite_db_bei,park_type_flag);
    }else{
        if(this->mysql_link->mySql_db.isOpen())
        {
            car_vehicle(QDateTime::currentDateTime().addSecs(-10800),&this->mysql_link->mySql_db,park_type_flag);
        }
    }
}

void MainWindow::on_pushButton_wiget2_5_clicked()
{
    if(sysInfo->model==3)
    {
        car_vehicle(QDateTime::currentDateTime().addSecs(-18000),&this->myDb->sqlite_db_bei,park_type_flag);
    }else{
        if(this->mysql_link->mySql_db.isOpen())
        {
            car_vehicle(QDateTime::currentDateTime().addSecs(-18000),&this->mysql_link->mySql_db,park_type_flag);
        }
    }
}

void MainWindow::on_pushButton_wiget2_up_clicked()//上一页
{
    int maxValue = ui->tableWidget_2->verticalScrollBar()->maximum(); // 当前SCROLLER最大显示值25
    nCurScroller = ui->tableWidget_2->verticalScrollBar()->value();

    if(nCurScroller>0)
        ui->tableWidget_2->verticalScrollBar()->setSliderPosition(nCurScroller-pageValue);
    else
        ui->tableWidget_2->verticalScrollBar()->setSliderPosition(maxValue);
}

void MainWindow::on_pushButton_wiget2_down_clicked()//下一页
{
    int maxValue = ui->tableWidget_2->verticalScrollBar()->maximum(); //当前SCROLLER最大显示值25
    nCurScroller = ui->tableWidget_2->verticalScrollBar()->value(); //获得当前scroller值

    if(nCurScroller<maxValue)
        ui->tableWidget_2->verticalScrollBar()->setSliderPosition(pageValue+nCurScroller);
    else
        ui->tableWidget_2->verticalScrollBar()->setSliderPosition(0);
}

void MainWindow::on_tool_xBtn_clicked()//
{
    //screen2=QPixmap::grabWindow(QApplication::desktop()->winId());
    //screen2.save("tian.png","png");
    if(day_flag==QString("day") || day_flag==QString("time"))
    {
        ui->stackedWidget->setCurrentIndex(2);
    }else{
        ui->stackedWidget->setCurrentIndex(1);
    }
    pic_name="images/picR.jpg";
    update();
}

bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
    if (obj == ui->lcdNumber)
    {
        if (event->type() == QEvent::MouseButtonPress)
        {
            Turn_Class();
            return true;
        } else {
            return false;
        }
    }
    else if (obj == ui->label_turn_begin)
    {
        if (event->type() == QEvent::MouseButtonPress)
        {
            //Turn_Class();
            QString date_str;
            date_str=ui->label_turn_begin->text();
            dateSet dateform(this);
            FORMDATE=QDateTime::fromString(date_str,"yyyy-MM-dd hh:mm");
            qDebug()<<"date=="<<FORMDATE<<date_str;
            dateform.setRedate(FORMDATE);
            dateform.exec();
            qDebug()<<"======="<<FORMDATE;
            ui->label_turn_begin->setText(FORMDATE.toString("yyyy-MM-dd hh:mm"));
            in_out_record();
            return true;
        } else {
            return false;
        }
    }
    else if (obj == ui->label_turn_end)
    {
        if (event->type() == QEvent::MouseButtonPress)
        {
            //Turn_Class();
            QString date_str;
            date_str=ui->label_turn_end->text();
            dateSet dateform(this);
            FORMDATE=QDateTime::fromString(date_str,"yyyy-MM-dd hh:mm");
            qDebug()<<"date=="<<FORMDATE<<date_str;
            dateform.setRedate(FORMDATE);
            dateform.exec();
            ui->label_turn_end->setText(FORMDATE.toString("yyyy-MM-dd hh:mm"));
            in_out_record();
            return true;
        } else {
            return false;
        }
    }
    else if (obj == ui->lcdNumber_2)
    {
        if (event->type() == QEvent::MouseButtonPress)
        {
            In_CarRecord();
            return true;
        } else {
            return false;
        }
    }
    else if (obj == ui->lineEdit_IN_CAR)
    {
        QWidget *fWidget = this->focusWidget();
        if ((event->type()==QEvent::MouseButtonPress) &&(obj==fWidget))//ui->lineEdit
        {
            w.showFullScreen();
            updatePosition();
            return true;
        }
        return QWidget::eventFilter(obj,event);
    }else{
        return MainWindow::eventFilter(obj, event);
    }
}

void MainWindow::on_pushButton_time_clicked()
{
    day_flag=QString("time");
    ui->groupBox->setTitle("查询已入时间（小时）");
    ui->stackedWidget->setCurrentIndex(3);
}

void MainWindow::on_pushButton_wiget2_2_clicked()
{
    if(sysInfo->model==3)
    {
        car_vehicle(QDateTime::currentDateTime().addSecs(-7200),&this->myDb->sqlite_db_bei,park_type_flag);
    }else{
        if(this->mysql_link->mySql_db.isOpen())
        {
            car_vehicle(QDateTime::currentDateTime().addSecs(-7200),&this->mysql_link->mySql_db,park_type_flag);
        }
    }
}

void MainWindow::on_pushButton_wiget2_4_clicked()
{
    if(sysInfo->model==3)
    {
        car_vehicle(QDateTime::currentDateTime().addSecs(-14400),&this->myDb->sqlite_db_bei,park_type_flag);
    }else{
        if(this->mysql_link->mySql_db.isOpen())
        {
            car_vehicle(QDateTime::currentDateTime().addSecs(-14400),&this->mysql_link->mySql_db,park_type_flag);
        }
    }
}

void MainWindow::on_pushButton_wiget2_6_clicked()
{
    if(sysInfo->model==3)
    {
        car_vehicle(QDateTime::currentDateTime().addSecs(-21600),&this->myDb->sqlite_db_bei,park_type_flag);
    }else{
        if(this->mysql_link->mySql_db.isOpen())
        {
            car_vehicle(QDateTime::currentDateTime().addSecs(-21600),&this->mysql_link->mySql_db,park_type_flag);
        }
    }
}

void MainWindow::on_pushButton_widget2_ok_clicked()
{
    ui->stackedWidget->setCurrentIndex(0);
    displayData_t info;
    ///bzero(&info,sizeof(info));
    int j;
    info.audioStr.clear();
    for(j=1;j<4;j++)
    {
        info.DispelayStr[j].clear();
    }
    CarInPicName.clear();
    pic_name="images/pic.png";
    update();
    if(hand_carIn.isEmpty())
    {
        return ;
    }
    if(sysInfo->model==3)
    {
        bool ren;
        ren=this->myDb->CarOutInfo(&this->myDb->sqlite_db,QString::number(sysInfo->vehicleFlag),hand_carIn,&Car_OutInfor);
        if(ren)
        {
            ui->label_parkTime->setText(Car_OutInfor.parkTime );//+ QString("分"));
            ui->label_beginT->setText(Car_OutInfor.beginTime);
            ui->label_endT->setText(Car_OutInfor.endTime);
            ui->lcdNumber->display(Car_OutInfor.money);
            QString car_ourtnum;
            car_ourtnum=hand_carIn;

            //QString sendauto=car_ourtnum.append("收费").append(QString::number(Car_OutInfor.money)).append("元");
            // QByteArray sendArray;
            // info.DispelayStr[1]="临时车";
            info.DispelayStr[2]=car_ourtnum;
            info.DispelayStr[3].append("收费").append(QString::number(Car_OutInfor.money)).append("元");
            int i=0;
            for(i=1;i<4;i++)
                info.audioStr.append(info.DispelayStr[i]);
            this->cameraOut->socket_short_display(&info);
        }
        hand_carIn.clear();
    }else{
        my_network->carOut(hand_carIn,Camera_picOut,QString::number(sysInfo->vehicleFlag));
        if(sysInfo->savePicture==1)
        {
            //filelink->copyFile(DIRTEMP,CAROUT,Camera_picOut);
            QString Pic_date=QDate::currentDate().toString("yyyyMMdd");
            filelink->copyFileToDate(Pic_date,CAROUT,Camera_picOut);
            this->myDb->inOutimage_insert(&this->myDb->sqlite_db,Camera_picOut,hand_carIn,Pic_date);
        }
        hand_carIn.clear();
    }
}

/*void MainWindow::car_inout_show(QDateTime endtime,QSqlDatabase *db) //车辆信息
{
    ui->label_turn_begin->setText(TurnClassTime.toString("yyyy-MM-dd hh:mm"));
    ui->label_turn_end->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm"));

    int ret;
    int car_num;
    float all_fee;
    QSqlQuery query,select_car;
    query= QSqlQuery(*db);
    select_car = QSqlQuery(*db);
    query.clear();
    query.prepare(QObject::tr("select count(*),sum(fee) from record_in_out where out_time >='%1' and status='%2'").arg(endtime.toString("yyyy-MM-dd hh:mm:ss")).arg(QString("已出")));
    query.exec();
    ret = query.next();
    if(ret==1)
    {
        car_num=query.value(0).toInt();
        all_fee=query.value(1).toFloat();
        ui->label_car_cunt->setText(QString("%1").arg(car_num));
        ui->lcdNumber_3->display(all_fee);
    }
    ui->tableWidget->setRowCount(car_num);
    ui->tableWidget->setColumnCount(5);
    QStringList headers;
    headers<<QString::fromUtf8("车号")<<QString::fromUtf8("入场时间")<<QString::fromUtf8("出场时间")<<QString::fromUtf8("停车时长")<<QString::fromUtf8("收费金额(元)");
    ui->tableWidget->setHorizontalHeaderLabels(headers);
    ui->tableWidget->setColumnWidth(0,80);
    ui->tableWidget->setColumnWidth(1,170);
    ui->tableWidget->setColumnWidth(2,170);
    ui->tableWidget->setColumnWidth(3,150);
    ui->tableWidget->setColumnWidth(4,150);

    select_car.exec(tr("select car_no,in_time,out_time,part_time,fee from record_in_out  where out_time >='%1' and status='%2'  order by out_time desc").arg(endtime.toString("yyyy-MM-dd hh:mm:ss")).arg("已出"));
    for(int i=0;select_car.next();i++)
    {
        QString car_no=select_car.value(0).toString();
        QString car_in=select_car.value(1).toString().replace(10,1," ");
        QString car_out=select_car.value(2).toString().replace(10,1," ");
        QString statu =select_car.value(3).toString();
        QString fee=select_car.value(4).toString();

        ui->tableWidget->setItem(i,0,new QTableWidgetItem(car_no));
        ui->tableWidget->setItem(i,1,new QTableWidgetItem(car_in));
        ui->tableWidget->setItem(i,2,new QTableWidgetItem(car_out));
        ui->tableWidget->setItem(i,3,new QTableWidgetItem(statu));
        ui->tableWidget->setItem(i,4,new QTableWidgetItem(fee));
    }
    ui->stackedWidget->setCurrentIndex(1);
}*/

void MainWindow::car_vehicle(QDateTime endtime,QSqlDatabase *db,int flag)
{
    int ret;
    int car_num;
    QSqlQuery query,select_car;
    QString count_res,item_res;
    query= QSqlQuery(*db);
    select_car = QSqlQuery(*db);
    if(flag==1)
    {
        count_res =  QObject::tr("select count(*) from record_in_out where in_time >='%1' and status='%2'").arg(endtime.toString("yyyy-MM-dd hh:mm:ss")).arg(QString("已入"));
        item_res =QObject::tr("select car_no,in_time,pass_no,in_image,card_type from record_in_out  where in_time >='%1' and status='%2'  order by in_time desc").arg(endtime.toString("yyyy-MM-dd hh:mm:ss")).arg(QString("已入"));
    }else if(flag==2){
        count_res =  QObject::tr("select count(*) from record_in_out where in_time >='%1' and status='%2' and card_type='%3'").arg(endtime.toString("yyyy-MM-dd hh:mm:ss")).arg(QString("已入")).arg("固定车");
        item_res =QObject::tr("select car_no,in_time,pass_no,in_image,card_type from record_in_out  where in_time >='%1' and status='%2' and card_type='%3'  order by in_time desc").arg(endtime.toString("yyyy-MM-dd hh:mm:ss")).arg(QString("已入")).arg("固定车");
    }else if(flag==3){
        count_res =  QObject::tr("select count(*) from record_in_out where in_time >='%1' and status='%2' and card_type='%3'").arg(endtime.toString("yyyy-MM-dd hh:mm:ss")).arg(QString("已入")).arg("临时车");
        item_res =QObject::tr("select car_no,in_time,pass_no,in_image,card_type from record_in_out  where in_time >='%1' and status='%2'  and card_type='%3' order by in_time desc").arg(endtime.toString("yyyy-MM-dd hh:mm:ss")).arg(QString("已入")).arg("临时车");
    }else if(flag==4){
        count_res =  QObject::tr("select count(*) from record_in_out where in_time >='%1' and status='%2' and card_type='%3'").arg(endtime.toString("yyyy-MM-dd hh:mm:ss")).arg(QString("已入")).arg("特殊车");
        item_res =QObject::tr("select car_no,in_time,pass_no,in_image,card_type from record_in_out  where in_time >='%1' and status='%2' and card_type='%3' order by in_time desc").arg(endtime.toString("yyyy-MM-dd hh:mm:ss")).arg(QString("已入")).arg("特殊车");
    }else{
        count_res =  QObject::tr("select count(*) from record_in_out where in_time >='%1' and status='%2'").arg(endtime.toString("yyyy-MM-dd hh:mm:ss")).arg(QString("已入"));
        item_res =QObject::tr("select car_no,in_time,pass_no,in_image,card_type from record_in_out  where in_time >='%1' and status='%2'  order by in_time desc").arg(endtime.toString("yyyy-MM-dd hh:mm:ss")).arg(QString("已入"));
    }

    query.clear();
    query.prepare(count_res);
    query.exec();
    ret = query.next();
    if(ret==1)
    {
        car_num=query.value(0).toInt();

    }else{
        car_num=0;
    }
    ui->tableWidget_2->setRowCount(car_num);
    ui->label_widgetcount->setText(QString("合计: %1条").arg(car_num));
    ui->tableWidget_2->setColumnCount(4);
    QStringList headers;
    headers<<QString::fromUtf8("车号")<<QString::fromUtf8("入场时间")<<QString::fromUtf8("编号")<<QString::fromUtf8("入场图片");
    ui->tableWidget_2->setHorizontalHeaderLabels(headers);
    ui->tableWidget_2->setColumnWidth(0,90);
    ui->tableWidget_2->setColumnWidth(1,150);
    ui->tableWidget_2->setColumnWidth(2,2);
    ui->tableWidget_2->setColumnWidth(3,2);

    select_car.prepare(item_res);
    select_car.exec();
    for(int i=0;select_car.next();i++)
    {
        QString car_no=select_car.value(0).toString();
        QString car_in=select_car.value(1).toString().replace(10,1," ").mid(0,16);
        QString car_out=select_car.value(2).toString();
        QString in_image=select_car.value(3).toString();
        QString type=select_car.value(4).toString();
        ui->tableWidget_2->setItem(i,0,new QTableWidgetItem(car_no));
        ui->tableWidget_2->setItem(i,1,new QTableWidgetItem(car_in));
        ui->tableWidget_2->setItem(i,2,new QTableWidgetItem(car_out));
        ui->tableWidget_2->setItem(i,3,new QTableWidgetItem(in_image));
        ui->tableWidget_2->setRowHeight(i,50);

        if( type!="固定车" )
        {
            QTableWidgetItem *item=new  QTableWidgetItem();
            item->setTextColor(QColor(Qt::red));
            item->setText(car_no);
            ui->tableWidget_2->setItem(i,0,item);
        }
    }
}

void MainWindow::Turn_Class()
{
    QDateTime end_dateT=QDateTime::currentDateTime();
    if(sysInfo->model==3)
    {
        car_inout_show(TurnClassTime,end_dateT,&this->myDb->sqlite_db_bei,park_type_flag);
        ui->label_turn_begin->setText(TurnClassTime.toString("yyyy-MM-dd hh:mm"));
        ui->label_turn_end->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm"));
        ui->stackedWidget->setCurrentIndex(1);
        pic_name="images/picR.jpg";
        update();
    }else{
        if(this->mysql_link->mySql_db.isOpen())
        {
            car_inout_show(TurnClassTime,end_dateT,&this->mysql_link->mySql_db,park_type_flag);
            ui->label_turn_begin->setText(TurnClassTime.toString("yyyy-MM-dd hh:mm"));
            ui->label_turn_end->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm"));
            ui->stackedWidget->setCurrentIndex(1);
            pic_name="images/picR.jpg";
            update();
        }else{
            //QMessageBox::warning(this, tr("提示"), tr("数据库打开失败"));
            car_inout_show(TurnClassTime,end_dateT,&this->myDb->sqlite_db_bei,park_type_flag);
            ui->label_turn_begin->setText(TurnClassTime.toString("yyyy-MM-dd hh:mm"));
            ui->label_turn_end->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm"));
            ui->stackedWidget->setCurrentIndex(1);
            pic_name="images/picR.jpg";
            update();
        }
    }
}

void MainWindow::In_CarRecord()
{
    if(sysInfo->model==3)
    {
        ui->stackedWidget->setCurrentIndex(2);
        ui->stackedWidget_2->setCurrentIndex(1);
        ui->label_InImage->setPixmap(QPixmap("./images/car.jpg"));
        car_vehicle(QDateTime(QDate::currentDate()),&this->myDb->sqlite_db_bei,park_type_flag);
        pic_name="images/picR.jpg";
        update();
    }else{
        if(mysql_link->mySql_db.isOpen())
        {
            QString car_name=FindCarIN(Car_OutVehicle);
            ui->stackedWidget->setCurrentIndex(2);
            ui->stackedWidget_2->setCurrentIndex(1);
            ui->label_InImage->setPixmap(QPixmap("./images/car.jpg"));
            if(CarOutError.isEmpty())
            {
                car_vehicle(QDateTime(QDate::currentDate()),&this->mysql_link->mySql_db,park_type_flag);
            }else{
                INcar_vehicle(&this->mysql_link->mySql_db,car_name);
            }
            pic_name="images/picR.jpg";
            update();
        }else{
            QMessageBox::warning(this, tr("提示"), tr("数据库打开失败"));
        }
    }
}

/*bool MainWindow::showMap(QString car_no)
{
    qDebug()<<tr("size of this carmap is : ")<< car_map.count();
    if(car_map.isEmpty())
    {
        return  false;
    }
    if(car_map.contains(car_no))
    {
        return true;
    }else{
        return false;
    }
}*/

int MainWindow::showMap(QString car_no,QString carFlag)
{
    qDebug()<<tr("size of this carmap is :")<< car_map.count();
    if(car_map.isEmpty())
    {
        return  0;
    }else{
        if(car_map.contains(car_no))
        {
            CarParkMap::Iterator it=car_map.find(car_no);
            qDebug()<<"*******"<<it.value().carName();
            if(it.value().carName()==carFlag)
            {
                return 1;
            }else{
                QDateTime created_time=it.value().surTime();
                QDateTime now_day=QDateTime::currentDateTime();
                int m=  created_time.secsTo(now_day);
                int n=sysInfo->heart-m;
                pass_flag_heart=n;
                return 2;
            }
        }else{
            return 0;
        }
    }
}

void MainWindow::map_carLink()
{
    /*QMap<QString,QDateTime>::iterator it; //遍历map
    QDateTime mmm=QDateTime::currentDateTime();
    for ( it = car_map.begin(); it != car_map.end(); ++it )
    {
        qDebug()<<tr( "%s:%s")<<it.key()<<it.value().secsTo(mmm); //用key()和data()分别获取“键”和“值”
        if(it.value().secsTo(mmm)>sysInfo->heart)
        {
          car_map.remove(it.key());
        }
    }*/
    if(sysInfo->passFlag==1)
    {
        if(car_map.count()==0)
        {
            return;
        }
        CarParkMap::Iterator itt;
        QDateTime mday=QDateTime::currentDateTime();
        for ( itt = car_map.begin(); itt != car_map.end(); ++itt )
        {
            QDateTime mod = itt.value().surTime();
            qDebug()<<itt.key()<<itt.value().carName()<<mod.secsTo(mday);
            if(mod.secsTo(mday) >sysInfo->heart)
            {
                car_map.remove(itt.key());
            }
        }
    }
}

void MainWindow::on_pushButton_allTime_clicked()
{
    day_flag=QString("Feetime");
    ui->groupBox->setTitle("查询已出时间(小时）");
    ui->stackedWidget->setCurrentIndex(3);
    pic_name="images/picR.jpg";
    update();
}

void MainWindow::DogLink()
{
    watch_dog->start();
}

bool MainWindow::win_read_ini()
{

    QFile file("camera.ini");
    QString as,bs,cs,ds;
    if(file.open(QFile::ReadOnly))
    {
        as=file.readLine().trimmed();
        bs=file.readLine().trimmed();
        cs=file.readLine().trimmed();
        ds=file.readLine().trimmed();
        file.close();
        if(ds =="1")
        {
            return false;
        }else{
            if(file.open(QFile::WriteOnly))
            {
                QTextStream out1(&file);
                out1<<as<<"\r\n"<<bs<<"\r\n"<<cs<<"\r\n"<<"1"<<"\r\n";
                out1.seek(out1.pos());//定位文件当前
                file.close();
            }
            return true;
        }
    }else{
        QFile file1("camera.ini");
        if(file1.open(QFile::WriteOnly))
        {
            QTextStream out1(&file1);
            out1<<"127.0.0.1"<<"\r\n"<<"127.0.0.1"<<"\r\n"<<"127.0.0.1"<<"\r\n"<<"1"<<"\r\n";
            out1.seek(out1.pos());//定位文件当前
            //file.write("\r\n");//换行符
            // ip="127.0.0.1";
            file1.close();
            return true;
        }
    }
}

void MainWindow::imagedir_remove()
{
    QDate deleday=QDate::currentDate().addDays(-29);
    QString dirname=deleday.toString("yyyyMMdd");
    QString deleteDir=sysInfo->path+"/"+dirname;
    this->myDb->inOutDir_move(&this->myDb->sqlite_db,dirname);
    filelink->removefilesindir(deleteDir);
}

void MainWindow::on_pushButton_inpic_clicked()
{
    if(!CarInPicName.isNull())
    {
        scroll= new scrollarea;
        scroll->show_image(CarInPicName);
        scroll->show();
    }
}

QString MainWindow::FindCarIN(QString carNo)
{
    QString tmp;
    int m=0;
    for(int j = 0; j < carNo.length(); j++)
    {
        if(carNo[j] > '0' && carNo[j] < '9')
        {
            if(m==2)
            {
                break;
            }
            tmp.append(carNo[j]);
            m++;
        }else{
            tmp.clear();
            m=0;
        }
    }
    tmp=QString("%")+tmp+QString("%");
    return tmp;
}

void MainWindow::INcar_vehicle(QSqlDatabase *db,QString car_no)
{
    int ret;
    int car_num;
    QSqlQuery query,select_car;
    query= QSqlQuery(*db);
    select_car = QSqlQuery(*db);
    query.clear();
    query.prepare(QObject::tr("select count(*) from record_in_out where car_no like '%1' and status='%2'").arg(car_no).arg(QString("已入")));
    query.exec();
    ret = query.next();

    if(ret==1)
    {
        car_num=query.value(0).toInt();
        ui->tableWidget_2->setRowCount(car_num);
        ui->label_widgetcount->setText(QString("合计: %1条").arg(car_num));
    }

    ui->tableWidget_2->setColumnCount(4);
    QStringList headers;
    headers<<QString::fromUtf8("车号")<<QString::fromUtf8("入场时间")<<QString::fromUtf8("编号")<<QString::fromUtf8("入场图片");
    ui->tableWidget_2->setHorizontalHeaderLabels(headers);
    ui->tableWidget_2->setColumnWidth(0,90);
    ui->tableWidget_2->setColumnWidth(1,150);
    ui->tableWidget_2->setColumnWidth(2,2);
    ui->tableWidget_2->setColumnWidth(3,2);

    select_car.prepare(QObject::tr("select car_no,in_time,pass_no,in_image from record_in_out  where car_no like '%1' and status='%2'  order by in_time desc").arg(car_no).arg(QString("已入")));
    select_car.exec();
    for(int i=0;select_car.next();i++)
    {
        QString car_no=select_car.value(0).toString();
        QString car_in=select_car.value(1).toString().replace(10,1," ");
        QString car_out=select_car.value(2).toString();
        QString in_image=select_car.value(3).toString();
        qDebug()<<"=========="<<car_in;
        ui->tableWidget_2->setItem(i,0,new QTableWidgetItem(car_no));
        ui->tableWidget_2->setItem(i,1,new QTableWidgetItem(car_in));
        ui->tableWidget_2->setItem(i,2,new QTableWidgetItem(car_out));
        ui->tableWidget_2->setItem(i,3,new QTableWidgetItem(in_image));
        ui->tableWidget_2->setRowHeight(i,50);
    }
}
void MainWindow::serIP_change()
{
    if(serIP_flag)
    {
        sysInfo->serverIp=ser_IP1;
        serIP_flag=false;
    }else{
        sysInfo->serverIp=ser_IP2;
        serIP_flag=true;
    }
}

void MainWindow::onHeaderClicked(int column)
{
    if(column ==1)
    {
        ui->tableWidget->sortByColumn(1);
    }else if(column ==2)
    {
        ui->tableWidget->sortByColumn(2);
    }
}

void MainWindow::Widget2Clicked(int column)
{
    if(column ==1)
    {
        ui->tableWidget_2->sortByColumn(1);
    }
}

void MainWindow::park_type_set(int flag)
{
    if(flag==1)
    {
        park_type_flag=1;
        ui->toolButton_AllCar->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_GuCar->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_LinCar->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_TeCar->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }else  if(flag==2)
    {
        park_type_flag=2;
        ui->toolButton_GuCar->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_AllCar->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_LinCar->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_TeCar->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }else  if(flag==3)
    {
        park_type_flag=3;
        ui->toolButton_LinCar->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_GuCar->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_AllCar->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_TeCar->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }else  if(flag==4)
    {
        park_type_flag=4;
        ui->toolButton_TeCar->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_GuCar->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_LinCar->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_AllCar->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
}

void MainWindow::park_model_set(int flag)
{
    if(flag==1)
    {
        ui->toolBtn_model1->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_model2->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_model3->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_model4->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }else  if(flag==2)
    {
        ui->toolBtn_model2->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_model1->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_model3->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_model4->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }else  if(flag==3)
    {
        ui->toolBtn_model3->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_model2->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_model1->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_model4->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }else  if(flag==4)
    {
        ui->toolBtn_model4->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_model2->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_model3->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_model1->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
}

void MainWindow::park_parktype_set(int flag)
{
    if(flag==1)
    {
        ui->toolBtn_parktype1->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_parktype2->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_parktype3->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_parktype4->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }else  if(flag==2)
    {
        ui->toolBtn_parktype2->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_parktype1->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_parktype3->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_parktype4->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }else  if(flag==3)
    {
        ui->toolBtn_parktype3->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_parktype2->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_parktype1->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_parktype4->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }else  if(flag==4)
    {
        ui->toolBtn_parktype4->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_parktype2->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_parktype3->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolBtn_parktype1->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
}

void MainWindow::park_camera_set(int flag)
{
    if(flag==1)
    {
        ui->toolButton_car_all->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_car_guding->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_gulin->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_gulinout->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_gulinall->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        sysInfo->park_camera=1;
    }else  if(flag==2)
    {
        ui->toolButton_car_guding->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_car_all->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_gulin->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_gulinout->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_gulinall->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        sysInfo->park_camera=2;
    }else  if(flag==3)
    {
        ui->toolButton_car_gulin->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_car_guding->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_all->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_gulinout->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_gulinall->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        sysInfo->park_camera=3;
    }else  if(flag==4)
    {
        ui->toolButton_car_gulinout->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_car_guding->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_gulin->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_all->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_gulinall->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        sysInfo->park_camera=4;
    }else  if(flag==5)
    {
        ui->toolButton_car_gulinall->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_car_guding->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_gulin->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_all->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_car_gulinout->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        sysInfo->park_camera=5;
    }
}

void MainWindow::park_pass_set(int flag)
{
    if(flag==0)
    {
        ui->toolBtn_pass0->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_pass1->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
    else{
        ui->toolBtn_pass1->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_pass0->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
}

void MainWindow::park_tempcarin_set(int flag)
{
    if(flag==0)
    {
        ui->toolBtn_tempcar0->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_tempcar1->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        sysInfo->tempCarIn=0;
    }
    else{
        ui->toolBtn_tempcar1->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_tempcar0->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        sysInfo->tempCarIn=1;
    }
}

void MainWindow::park_vehicle_set(int flag)
{
    if(flag==0)
    {
        ui->toolBtn_vehicle0->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_vehicle1->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
    else{
        ui->toolBtn_vehicle1->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_vehicle0->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
}

void MainWindow::park_savepic_set(int flag)
{
    if(flag==0)
    {
        ui->toolBtn_savepic0->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_savepic1->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
    else{
        ui->toolBtn_savepic1->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_savepic0->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
}

void MainWindow::park_firstdown_set(int flag)
{
    if(flag==0)
    {
        ui->toolBtn_firstdown0->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_firstdown1->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
    else{
        ui->toolBtn_firstdown1->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolBtn_firstdown0->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
}

void MainWindow::park_fee_set(int flag)
{
    if(flag==0)
    {
        ui->toolButton_fee_half->setStyleSheet("QToolButton{color:black;background-color:lightblue;}");
        ui->toolButton_fee_one->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_fee_tall->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
    else if(flag==1){
        ui->toolButton_fee_half->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_fee_one->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_fee_tall->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
    else if(flag==2){
        ui->toolButton_fee_one->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_fee_half->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_fee_tall->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
    else if(flag==3){
        ui->toolButton_fee_tall->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_fee_one->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->toolButton_fee_half->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
    }
    park_fee_flag=flag;
}

void MainWindow::park_passwd(int flag)
{
    if(flag==0)//验证密码
    {
        passwd_flag=0;
        ui->groupBox_pass->setTitle("输入密码");
        ui->toolButton_passwd->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_passwdChangge->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->lineEdit_passwd->clear();
        ui->lcdNumber_passwd->display(0);
        ui->label_passwd_message->clear();

    }else if(flag==1)//输入当前密码
    {
        passwd_flag=1;
        ui->groupBox_pass->setTitle("输入当前密码");
        ui->toolButton_passwdChangge->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_passwd->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        ui->lineEdit_passwd1->clear();
        ui->lcdNumber_passwd->display(0);
        ui->label_passwd_message->clear();
    }
    else if(flag==2)//输入新密码
    {
        passwd_flag=2;
        ui->groupBox_pass->setTitle("输入新密码");
        ui->lineEdit_passwd2->clear();
        ui->lcdNumber_passwd->display(0);
    }
    else if(flag==3)//再次输入新密码
    {
        passwd_flag=3;
        ui->groupBox_pass->setTitle("再次输入新密码");
        ui->lineEdit_passwd3->clear();
        ui->lcdNumber_passwd->display(0);
    }
}

void MainWindow::input_fee(int flat)
{
    QString input;
    switch(flat)
    {
    case  0:
        input=QString::number(0);
        break;
    case  1:
        input=QString::number(1);
        break;
    case  2:
        input=QString::number(2);
        break;
    case  3:
        input=QString::number(3);
        break;
    case  4:
        input=QString::number(4);
        break;
    case  5:
        input=QString::number(5);
        break;
    case  6:
        input=QString::number(6);
        break;
    case  7:
        input=QString::number(7);
        break;
    case  8:
        input=QString::number(8);
        break;
    case  9:
        input=QString::number(9);
        break;
    case  10:
        input=QString(".");
        break;
    default:
        break;
    }
    if(park_fee_flag==1)
    {
        if(flat==11)
        {
            ui->lineEdit_fee_half->clear();
            ui->lcdNumber_fee_half->display(0);
        }else{
            ui->lineEdit_fee_half->insert(input);
            ui->lcdNumber_fee_half->display(ui->lineEdit_fee_half->text());
        }
    }else  if(park_fee_flag==2)
    {
        if(flat==11)
        {
            ui->lineEdit_fee_one->clear();
            ui->lcdNumber_fee_one->display(0);
        }else{
            ui->lineEdit_fee_one->insert(input);
            ui->lcdNumber_fee_one->display(ui->lineEdit_fee_one->text());
        }
    }else  if(park_fee_flag==3)
    {
        if(flat==11)
        {
            ui->lineEdit_fee_tall->clear();
            ui->lcdNumber_fee_tall->display(0);
        }else{
            ui->lineEdit_fee_tall->insert(input);
            ui->lcdNumber_fee_tall->display(ui->lineEdit_fee_tall->text());
        }
    }
}

void MainWindow::passwd_input_fee(int flat)
{
    QString input;
    switch(flat)
    {
    case  0:
        input=QString::number(0);
        break;
    case  1:
        input=QString::number(1);
        break;
    case  2:
        input=QString::number(2);
        break;
    case  3:
        input=QString::number(3);
        break;
    case  4:
        input=QString::number(4);
        break;
    case  5:
        input=QString::number(5);
        break;
    case  6:
        input=QString::number(6);
        break;
    case  7:
        input=QString::number(7);
        break;
    case  8:
        input=QString::number(8);
        break;
    case  9:
        input=QString::number(9);
        break;
    default:
        break;
    }
    if(passwd_flag==0)
    {
        ui->lineEdit_passwd->insert(input);
        ui->lcdNumber_passwd->display(ui->lineEdit_passwd->text());
    }
    else if(passwd_flag==1)
    {
        ui->lineEdit_passwd1->insert(input);
        ui->lcdNumber_passwd->display(ui->lineEdit_passwd1->text());
    }else  if(passwd_flag==2)
    {
        ui->lineEdit_passwd2->insert(input);
        ui->lcdNumber_passwd->display(ui->lineEdit_passwd2->text());
    }else  if(passwd_flag==3)
    {
        ui->lineEdit_passwd3->insert(input);
        ui->lcdNumber_passwd->display(ui->lineEdit_passwd3->text());
    }
}

void MainWindow::stackpage()
{
    int m=ui->stackedWidget_3->currentIndex();
    int n=ui->stackedWidget_3->count();
    ui->label_pagenum->setText(QString("页数 ")+QString::number(m+1)+QString("/")+QString::number(n));
}

void MainWindow::on_toolButton_AllCar_clicked()
{
    park_type_set(1);
}

void MainWindow::on_toolButton_GuCar_clicked()
{
    park_type_set(2);
}

void MainWindow::on_toolButton_LinCar_clicked()
{
    park_type_set(3);
}

void MainWindow::on_toolButton_TeCar_clicked()
{
    park_type_set(4);
}

void MainWindow::on_pushButton_set_clicked()
{
    ui->stackedWidget->setCurrentIndex(5);
    ui->lineEdit_passwd->clear();
    ui->lcdNumber_passwd->display(0);
    park_passwd(0);
    pic_name="images/picR.jpg";
    update();
}

void MainWindow::on_toolbtn_quit_clicked()
{
    ui->stackedWidget->setCurrentIndex(0);
    pic_name="images/pic.png";
    update();
}

void MainWindow::on_toolbtn_1_clicked()
{
    ui->lineEdit_seart->insert(QString::number(1));
    ui->lcdNumber_CarSeat->display(ui->lineEdit_seart->text());
}

void MainWindow::on_toolbtn_2_clicked()
{
    ui->lineEdit_seart->insert(QString::number(2));
    ui->lcdNumber_CarSeat->display(ui->lineEdit_seart->text());
}

void MainWindow::on_toolbtn_3_clicked()
{
    ui->lineEdit_seart->insert(QString::number(3));
    ui->lcdNumber_CarSeat->display(ui->lineEdit_seart->text());
}

void MainWindow::on_toolbtn_4_clicked()
{
    ui->lineEdit_seart->insert(QString::number(4));
    ui->lcdNumber_CarSeat->display(ui->lineEdit_seart->text());
}

void MainWindow::on_toolbtn_5_clicked()
{
    ui->lineEdit_seart->insert(QString::number(5));
    ui->lcdNumber_CarSeat->display(ui->lineEdit_seart->text());
}

void MainWindow::on_toolbtn_6_clicked()
{
    ui->lineEdit_seart->insert(QString::number(6));
    ui->lcdNumber_CarSeat->display(ui->lineEdit_seart->text());
}

void MainWindow::on_toolbtn_7_clicked()
{
    ui->lineEdit_seart->insert(QString::number(7));
    ui->lcdNumber_CarSeat->display(ui->lineEdit_seart->text());
}

void MainWindow::on_toolbtn_8_clicked()
{
    ui->lineEdit_seart->insert(QString::number(8));
    ui->lcdNumber_CarSeat->display(ui->lineEdit_seart->text());
}

void MainWindow::on_toolbtn_9_clicked()
{
    ui->lineEdit_seart->insert(QString::number(9));
    ui->lcdNumber_CarSeat->display(ui->lineEdit_seart->text());
}

void MainWindow::on_toolbtn_0_clicked()
{
    ui->lineEdit_seart->insert(QString::number(0));
    ui->lcdNumber_CarSeat->display(ui->lineEdit_seart->text());
}

void MainWindow::on_toolbtn_clear_clicked()
{
    ui->lineEdit_seart->clear();
    ui->lcdNumber_CarSeat->display(0);
}

void MainWindow::on_pushButton_setting_up_clicked()
{
    int m=ui->stackedWidget_3->currentIndex();
    int n=ui->stackedWidget_3->count();
    if(m==0)
    {
        ui->stackedWidget_3->setCurrentIndex(n);
    }else{
        ui->stackedWidget_3->setCurrentIndex(m-1);
    }
    stackpage();
}

void MainWindow::on_pushButton_setting_down_clicked()
{
    int m=ui->stackedWidget_3->currentIndex();
    int n=ui->stackedWidget_3->count();
    if(m==n)
    {
        ui->stackedWidget_3->setCurrentIndex(0);
    }else{
        ui->stackedWidget_3->setCurrentIndex(m+1);
    }
    stackpage();
}

void MainWindow::on_toolButton_fee_half_clicked()
{
    park_fee_set(1);
}

void MainWindow::on_toolButton_fee_one_clicked()
{
    park_fee_set(2);
}

void MainWindow::on_toolButton_fee_tall_clicked()
{
    park_fee_set(3);
}

void MainWindow::on_toolButton_fee0_clicked()
{
    input_fee(0);
}

void MainWindow::on_toolButton_fee1_clicked()
{
    input_fee(1);
}

void MainWindow::on_toolButton_fee2_clicked()
{
    input_fee(2);
}

void MainWindow::on_toolButton_fee3_clicked()
{
    input_fee(3);
}

void MainWindow::on_toolButton_fee4_clicked()
{
    input_fee(4);
}

void MainWindow::on_toolButton_fee5_clicked()
{
    input_fee(5);
}

void MainWindow::on_toolButton_fee6_clicked()
{
    input_fee(6);
}

void MainWindow::on_toolButton_fee7_clicked()
{
    input_fee(7);
}

void MainWindow::on_toolButton_fee8_clicked()
{
    input_fee(8);
}

void MainWindow::on_toolButton_fee9_clicked()
{
    input_fee(9);
}

void MainWindow::on_toolButton_fee10_clicked()
{
    input_fee(10);
}

void MainWindow::on_toolButton_fee_clear_clicked()
{
    input_fee(11);
}

void MainWindow::on_toolButton_passwd_clicked()
{
    park_passwd(0);
}

void MainWindow::on_toolButton_passwdChangge_clicked()
{
    park_passwd(1);
}

void MainWindow::on_tool_Btn_pass_ok_clicked()//密码验证确认
{
    if(passwd_flag==0)
    {
        if(ui->lineEdit_passwd->text()==QString("6269768"))
        {
            ui->stackedWidget->setCurrentIndex(4);
            ui->stackedWidget_3->setCurrentIndex(0);
            stackpage();
        }else{
            QString name=myDb->userNameCheck(&this->myDb->sqlite_db);
            if(!name.isEmpty() && name==ui->lineEdit_passwd->text())
            {
                ui->stackedWidget->setCurrentIndex(4);
                ui->stackedWidget_3->setCurrentIndex(0);
                stackpage();
            }else{
                ui->label_passwd_message->setText("密码输入错误");
            }
        }
    }else if(passwd_flag==1)
    {

    }else if(passwd_flag==2)
    {

    }else if(passwd_flag==3)
    {

    }
}

void MainWindow::on_tool_Btn_back_clicked()//密码修改返回
{
    ui->stackedWidget->setCurrentIndex(1);
}

void MainWindow::on_tool_tui_clicked()//密码修改回退
{
    switch(passwd_flag)
    {
    case  0:
        ui->lineEdit_passwd->backspace();
        if(ui->lineEdit_passwd->text().isEmpty())
        {
            ui->lcdNumber_passwd->display(0);
        }else{
            ui->lcdNumber_passwd->display(ui->lineEdit_passwd->text());
        }
        break;
    case  1:
        ui->lineEdit_passwd1->backspace();
        if(ui->lineEdit_passwd1->text().isEmpty())
        {
            ui->lcdNumber_passwd->display(0);
        }else{
            ui->lcdNumber_passwd->display(ui->lineEdit_passwd1->text());
        }
        break;
    case  2:
        ui->lineEdit_passwd2->backspace();
        if(ui->lineEdit_passwd2->text().isEmpty())
        {
            ui->lcdNumber_passwd->display(0);
        }else{
            ui->lcdNumber_passwd->display(ui->lineEdit_passwd2->text());
        }
        break;
    case  3:
        ui->lineEdit_passwd3->backspace();
        if(ui->lineEdit_passwd3->text().isEmpty())
        {
            ui->lcdNumber_passwd->display(0);
        }else{
            ui->lcdNumber_passwd->display(ui->lineEdit_passwd3->text());
        }
        break;
    default:
        break;
    }
}

void MainWindow::on_tool_clear_clicked()//密码修改清空
{
    switch(passwd_flag)
    {
    case  0:
        ui->lineEdit_passwd->clear();
        break;
    case  1:
        ui->lineEdit_passwd1->clear();
        break;
    case  2:
        ui->lineEdit_passwd2->clear();
        break;
    case  3:
        ui->lineEdit_passwd3->clear();
        break;
    default:
        break;
    }
    ui->lcdNumber_passwd->display(0);
}

void MainWindow::on_tool_Btn_pass2_clicked()
{
    passwd_input_fee(2);
}

void MainWindow::on_tool_Btn_pass3_clicked()
{
    passwd_input_fee(3);
}

void MainWindow::on_tool_Btn_pass4_clicked()
{
    passwd_input_fee(4);
}

void MainWindow::on_tool_Btn_pass5_clicked()
{
    passwd_input_fee(5);
}

void MainWindow::on_tool_Btn_pass6_clicked()
{
    passwd_input_fee(6);
}

void MainWindow::on_tool_Btn_pass7_clicked()
{
    passwd_input_fee(7);
}

void MainWindow::on_tool_Btn_pass8_clicked()
{
    passwd_input_fee(8);
}

void MainWindow::on_tool_Btn_pass9_clicked()
{
    passwd_input_fee(9);
}

void MainWindow::on_tool_Btn_pass0_clicked()
{
    passwd_input_fee(0);
}

void MainWindow::on_tool_Btn_pass1_clicked()
{
    passwd_input_fee(1);
}

void MainWindow::on_toolButton_car_all_clicked()//ZI动起杠全部车
{
    park_camera_set(1);
}

void MainWindow::on_toolButton_car_guding_clicked()//ZI动起杠固定车
{
    park_camera_set(2);
}

void MainWindow::on_toolButton_car_gulin_clicked()//ZI动起杠临时车
{
    park_camera_set(3);
}

void MainWindow::on_toolButton_car_gulinout_clicked()//ZI动起杠临时车出
{
    park_camera_set(4);
}

void MainWindow::on_toolBtn_tempcar1_clicked()//临时车允许进入
{
    park_tempcarin_set(1);
}

void MainWindow::on_toolBtn_tempcar0_clicked()//临时车不允许进入
{
    park_tempcarin_set(0);
}

void MainWindow::on_toolButton_car_gulinall_clicked()//自动起杠临时车入出
{
    park_camera_set(5);
}

void MainWindow::quit_carNumberIn()
{
    timer_quit_carNumberIn->stop();
    carNumberIn_flag=true;
}

void MainWindow::quit_carNumberOut()
{
    timer_quit_carNumberOut->stop();
    carNumberOut_flag=true;
}

void MainWindow::write_back_str(QString str)
{   //数据写回
    QWidget *fWidget = this->focusWidget();
    QLineEdit *sel_line_edit= qobject_cast<QLineEdit*>(fWidget);
    if(str=="Backspace")
    {
        sel_line_edit->backspace();
    }
    else if(str=="clean")
    {
        sel_line_edit->clear();
    }
    else
    {
        sel_line_edit->insert(str);
    }
}

void MainWindow::updatePosition()
{   //显示在当前输入框下
    QWidget *widget = focusWidget();
    if (!widget)
    { return;}
    else if(widget==ui->lineEdit_IN_CAR)
    {
        QRect widgetRect = widget->rect();
        QPoint panelPos = QPoint(widgetRect.left() +30, widgetRect.bottom() + 2);
        panelPos = widget->mapToGlobal(panelPos);
        w.move(panelPos);
    }
}

void MainWindow::on_lineEdit_IN_CAR_textChanged(const QString &arg1)
{
    QString car_name=QString("%")+arg1+QString("%");
    if(arg1.isEmpty())
    {
        if(sysInfo->model==3)
        {
            car_vehicle(QDateTime(QDate::currentDate()),&this->myDb->sqlite_db_bei,park_type_flag);
        }else{
            if(this->mysql_link->mySql_db.isOpen())
            {
                if(CarOutError.isEmpty())
                {
                    car_vehicle(QDateTime(QDate::currentDate()),&this->mysql_link->mySql_db,park_type_flag);
                }else{
                    INcar_vehicle(&this->mysql_link->mySql_db,car_name);
                }
            }
        }
    }else{
        if(sysInfo->model==3)
        {
            INcar_vehicle(&this->myDb->sqlite_db_bei,car_name);
        }else{
            if(this->mysql_link->mySql_db.isOpen())
            {
                INcar_vehicle(&this->mysql_link->mySql_db,car_name);
            }
        }
    }
}

void MainWindow::on_pushButton_form_ok_clicked()
{
    QString str,mtr;
    str=ui->timeEdit_begin->time().toString();
    mtr=ui->timeEdit_end->time().toString();
    QFile file1("camera.ini");
    if(file1.open(QFile::WriteOnly))
    {
        QTextStream out1(&file1);
        out1<<str<<"\r\n"<<mtr<<"\r\n"<<park_form_flag;
        out1.seek(out1.pos());//定位文件当前
        file1.close();
    }
}

void MainWindow::park_form_set(QString flag)
{
    if(flag=="Y")
    {
        ui->toolButton_form_y->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_form_n->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        park_form_flag="Y";
    }
    else{
        ui->toolButton_form_n->setStyleSheet("QToolButton{color:white;background-color:green;}");
        ui->toolButton_form_y->setStyleSheet("QToolButton{color:blak;background-color:lightblue;}");
        park_form_flag="N";
    }
}

void MainWindow::on_toolButton_form_y_clicked()
{
    park_form_set("Y");
}

void MainWindow::on_toolButton_form_n_clicked()
{
    park_form_set("N");
}

void MainWindow::in_out_record()
{
    QString start_time=ui->label_turn_begin->text().trimmed().append(":00");
    QString end_time=ui->label_turn_end->text().trimmed().append(":00");
    QDateTime my_day,end_day;
    my_day=QDateTime::fromString(start_time,"yyyy-MM-dd hh:mm:ss");
    end_day=QDateTime::fromString(end_time,"yyyy-MM-dd hh:mm:ss");
    if(sysInfo->model==3)
    {
        car_inout_show(my_day,end_day,&this->myDb->sqlite_db_bei,park_type_flag);
    }else{
        if(this->mysql_link->mySql_db.isOpen())
        {

            car_inout_show(my_day,end_day,&this->mysql_link->mySql_db,park_type_flag);
        }else{
            car_inout_show(my_day,end_day,&this->myDb->sqlite_db_bei,park_type_flag);
            //QMessageBox::warning(this, tr("提示"), tr("数据库打开失败"));
            return;
        }
    }
}
